diff --git a/.changeset/33730-skills-query-hook-examples.md b/.changeset/33730-skills-query-hook-examples.md new file mode 100644 index 00000000000..c54417e4989 --- /dev/null +++ b/.changeset/33730-skills-query-hook-examples.md @@ -0,0 +1,8 @@ +--- +'@objectstack/skills': patch +--- + +Clause-②: no +Metadata-protocol: none + +The published query and hook skill examples now filter on the platform's `owner_id` column with `{current_user_id}`, and the hook `find` example reads the caller's id from `ctx.session?.userId` instead of an unbound variable. diff --git a/skills/objectstack-data/references/data-hooks.md b/skills/objectstack-data/references/data-hooks.md index 93990109626..95f1acdf951 100644 --- a/skills/objectstack-data/references/data-hooks.md +++ b/skills/objectstack-data/references/data-hooks.md @@ -295,6 +295,8 @@ same DSL as the [objectstack-query](../../objectstack-query/SKILL.md) skill: await ctx.api.object('candidate').findOne({ where: { id: ctx.result.id } }); await ctx.api.object('candidate').find({ where: { stage: 'hired' } }); await ctx.api.object('invoice').count({ where: { amount: { $gte: 1000 } } }); +const uid = ctx.session?.userId; +if (!uid) return; await ctx.api.object('task').find({ where: { $and: [{ done: false }, { owner_id: uid }] } }); ``` diff --git a/skills/objectstack-query/rules/filters.md b/skills/objectstack-query/rules/filters.md index a55ddd2b310..2f432bcf8c8 100644 --- a/skills/objectstack-query/rules/filters.md +++ b/skills/objectstack-query/rules/filters.md @@ -163,8 +163,7 @@ where: { period boundaries like `{current_month_start}`, `{last_quarter_end}`, `{next_year_start}` (and bare aliases like `{month_start}`). - **Parameterised tokens:** `{N__ago}` / `{N__from_now}` with - units `minute|hour|day|week|month|year` — e.g. `{30_days_ago}`, - `{2_weeks_from_now}`. + units `minute|hour|day|week|month|year` — e.g. `{2_weeks_from_now}`. - **Both spellings parse:** `{today}` and `${today}` are the same token (`DATE_MACRO_WRAPPED_RE` is `/^\$?\{([a-zA-Z0-9_]+)\}$/`, and the context tokens share it). @@ -174,7 +173,7 @@ where: { user's id and the active organization id. ```typescript -where: { owner: '{current_user_id}', close_date: { $gte: '{current_year_start}' } } +where: { owner_id: '{current_user_id}', close_date: { $gte: '{current_year_start}' } } ``` **Scope:** tokens expand on **both** sides of the wire — client-side by