@standards/client 1.0.0-alpha.442 → 1.0.0-alpha.443

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -41,7 +41,7 @@ const result = await standards.bundles.sync(status);
41
41
  // { applied: false, hash } when the workspace already holds this version: one GET, no write.
42
42
  ```
43
43
 
44
- Objects you sync are **system**: users can add their own attributes and views on top, but cannot delete or retype yours. Remove an object from the bundle and it is demoted to a custom object — its records survive. Never call `createStandards` with an API key in browser code; it refuses to.
44
+ Objects you sync are **system**: users can add their own attributes and views on top, but cannot delete or retype yours. Remove an attribute or an object from the bundle and `bundles.sync` holds the removal, listed in `pendingRemovals` of the sync that pushed the change (a later sync of the same hash is not sent and returns `pendingRemovals: []`), until a person confirms it: `standards.bundles.syncPreview(status)` returns the `fingerprint` and, for a key holding `architect:delete`, the `totalRecords` the removal deletes; `standards.bundles.sync(status, { fingerprint, confirmedRecords })` then removes the attribute with its values, the object with its records. Never call `createStandards` with an API key in browser code; it refuses to.
45
45
 
46
46
  ## 3. Typed records
47
47
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { E as TransportConfig, r as InProcessTransport, t as AppClient, w as OperationTransport, y as HttpTransport } from "./app-t-7y8Oio.mjs";
3
- import { AggregateRecordsOptions, BundleBuilder, ExtractRecord, ExtractRecordInputStrict, ExtractRecordUpdateStrict, FilterRule, ObjectBuilderLike, RecordAccessRole, RecordAggregates, RecordAudience, RuleValue, SchemaSourceResolution, SyncBundleResult } from "@standards/schema";
3
+ import { AggregateRecordsOptions, BundleBuilder, BundleSyncPreview, ExtractRecord, ExtractRecordInputStrict, ExtractRecordUpdateStrict, FilterRule, ObjectBuilderLike, RecordAccessRole, RecordAggregates, RecordAudience, RuleValue, SchemaSourceResolution, SyncBundleResult } from "@standards/schema";
4
4
  import { ActorId } from "@standards/schema/api";
5
5
  /**
6
6
  * What a sync carries besides the bundle itself.
@@ -12,11 +12,26 @@ import { ActorId } from "@standards/schema/api";
12
12
  */
13
13
  interface SyncBundleOptions {
14
14
  resolutions?: SchemaSourceResolution[];
15
+ /**
16
+ * The sync preview's fingerprint (`bundles.syncPreview`): with
17
+ * `confirmedRecords`, the sync also applies the removals it previewed.
18
+ * Without them, it applies everything else and returns the removals in
19
+ * `pendingRemovals`.
20
+ */
21
+ fingerprint?: string;
22
+ /** The records the preview counted for its removals, as the person confirmed them. */
23
+ confirmedRecords?: number;
15
24
  }
16
25
  /** Both calls are contract operations, on any transport. */
17
26
  type SyncTransport = Pick<HttpTransport, "call">;
18
- /** GET the installed summary; PUT the built bundle when its hash, label, description or uses differ, or it was never synced. */
27
+ /**
28
+ * GET the installed summary; PUT the built bundle when its hash, label,
29
+ * description or uses differ, or it was never synced. A confirmation is
30
+ * always PUT.
31
+ */
19
32
  declare function syncBundle(transport: SyncTransport, bundle: BundleBuilder<string, readonly ObjectBuilderLike[]>, options?: SyncBundleOptions): Promise<SyncBundleResult>;
33
+ /** What syncing the bundle would do: its pieces, its removals and the fingerprint to confirm them with. */
34
+ declare function previewBundleSync(transport: SyncTransport, bundle: BundleBuilder<string, readonly ObjectBuilderLike[]>): Promise<BundleSyncPreview>;
20
35
  /** `daily-stats` → `dailyStats`. Object names are kebab-case (enforced by the builder). */
21
36
  type CamelCase<S extends string> = S extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<CamelCase<Tail>>}` : S;
22
37
  type Attr<TBuilder> = keyof ExtractRecord<TBuilder> & string;
@@ -255,6 +270,7 @@ type AnyBundle = BundleBuilder<string, readonly ObjectBuilderLike[]>;
255
270
  /** The object builders of every bundle in a tuple: what the typed client infers from. */
256
271
  type ObjectsOfBundles<TBundles extends readonly AnyBundle[]> = TBundles[number]["objectBuilders"];
257
272
  type ContractSync = AppClient["bundles"]["sync"];
273
+ type ContractSyncPreview = AppClient["bundles"]["syncPreview"];
258
274
  /** `bundles.sync`, either way: from your bundle's builder, or the contract's call. */
259
275
  interface BundlesSync {
260
276
  /**
@@ -265,14 +281,22 @@ interface BundlesSync {
265
281
  /** The contract's call, with an artifact you built yourself. */
266
282
  (...args: Parameters<ContractSync>): ReturnType<ContractSync>;
267
283
  }
284
+ /** `bundles.syncPreview`, either way: from your bundle's builder, or the contract's call. */
285
+ interface BundlesSyncPreview {
286
+ /** Build `bundle` and preview its sync: its pieces, its removals and the fingerprint that confirms them. */
287
+ (bundle: AnyBundle): Promise<BundleSyncPreview>;
288
+ /** The contract's call, with an artifact you built yourself. */
289
+ (...args: Parameters<ContractSyncPreview>): ReturnType<ContractSyncPreview>;
290
+ }
268
291
  /**
269
292
  * The client: every operation of the contract at the root, by group and
270
293
  * verb (`decisions.list`, `users.get`, `files.upload`…), with your bundles'
271
294
  * objects beside them as typed queries (see {@link StandardsOf}).
272
295
  */
273
296
  type Standards = Omit<AppClient, "bundles"> & {
274
- readonly bundles: Omit<AppClient["bundles"], "sync"> & {
297
+ readonly bundles: Omit<AppClient["bundles"], "sync" | "syncPreview"> & {
275
298
  readonly sync: BundlesSync;
299
+ readonly syncPreview: BundlesSyncPreview;
276
300
  };
277
301
  /** Untyped access to an object the code does not declare (created at runtime). */
278
302
  from(objectName: string): UntypedRecordsQuery;
@@ -332,4 +356,4 @@ declare function createStandards<const TBundles extends readonly AnyBundle[]>(co
332
356
  bundles: TBundles;
333
357
  }): StandardsOf<ObjectsOfBundles<TBundles>>;
334
358
  declare function createStandards(config?: StandardsConfig): Standards;
335
- export { SyncBundleOptions as A, UntypedBuilder as C, UpdateManyResult as D, UpdateManyError as E, syncBundle as M, createRecordsQuery as O, RecordsQuery as S, UpdateManyEntry as T, RecordInput as _, ObjectsOfBundles as a, RecordsAggregateOptions as b, StandardsOf as c, CreateManyError as d, CreateManyResult as f, RecordCreateOptions as g, FetchResult as h, ObjectsOf as i, SyncTransport as j, CamelCase as k, StandardsTransport as l, DeleteManyResult as m, AnyBundle as n, Standards as o, DeleteManyError as p, BundlesSync as r, StandardsConfig as s, ActingStandards as t, createStandards as u, RecordUpdate as v, UntypedRecordsQuery as w, RecordsExportOptions as x, RecordUpdateOptions as y };
359
+ export { CamelCase as A, RecordsQuery as C, UpdateManyError as D, UpdateManyEntry as E, SyncTransport as M, previewBundleSync as N, UpdateManyResult as O, syncBundle as P, RecordsExportOptions as S, UntypedRecordsQuery as T, RecordCreateOptions as _, ObjectsOf as a, RecordUpdateOptions as b, StandardsConfig as c, createStandards as d, CreateManyError as f, FetchResult as g, DeleteManyResult as h, BundlesSyncPreview as i, SyncBundleOptions as j, createRecordsQuery as k, StandardsOf as l, DeleteManyError as m, AnyBundle as n, ObjectsOfBundles as o, CreateManyResult as p, BundlesSync as r, Standards as s, ActingStandards as t, StandardsTransport as u, RecordInput as v, UntypedBuilder as w, RecordsAggregateOptions as x, RecordUpdate as y };
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { E as TransportConfig, r as InProcessTransport, t as AppClient, w as OperationTransport, y as HttpTransport } from "./app-t-7y8Oio.js";
3
- import { AggregateRecordsOptions, BundleBuilder, ExtractRecord, ExtractRecordInputStrict, ExtractRecordUpdateStrict, FilterRule, ObjectBuilderLike, RecordAccessRole, RecordAggregates, RecordAudience, RuleValue, SchemaSourceResolution, SyncBundleResult } from "@standards/schema";
3
+ import { AggregateRecordsOptions, BundleBuilder, BundleSyncPreview, ExtractRecord, ExtractRecordInputStrict, ExtractRecordUpdateStrict, FilterRule, ObjectBuilderLike, RecordAccessRole, RecordAggregates, RecordAudience, RuleValue, SchemaSourceResolution, SyncBundleResult } from "@standards/schema";
4
4
  import { ActorId } from "@standards/schema/api";
5
5
  /**
6
6
  * What a sync carries besides the bundle itself.
@@ -12,11 +12,26 @@ import { ActorId } from "@standards/schema/api";
12
12
  */
13
13
  interface SyncBundleOptions {
14
14
  resolutions?: SchemaSourceResolution[];
15
+ /**
16
+ * The sync preview's fingerprint (`bundles.syncPreview`): with
17
+ * `confirmedRecords`, the sync also applies the removals it previewed.
18
+ * Without them, it applies everything else and returns the removals in
19
+ * `pendingRemovals`.
20
+ */
21
+ fingerprint?: string;
22
+ /** The records the preview counted for its removals, as the person confirmed them. */
23
+ confirmedRecords?: number;
15
24
  }
16
25
  /** Both calls are contract operations, on any transport. */
17
26
  type SyncTransport = Pick<HttpTransport, "call">;
18
- /** GET the installed summary; PUT the built bundle when its hash, label, description or uses differ, or it was never synced. */
27
+ /**
28
+ * GET the installed summary; PUT the built bundle when its hash, label,
29
+ * description or uses differ, or it was never synced. A confirmation is
30
+ * always PUT.
31
+ */
19
32
  declare function syncBundle(transport: SyncTransport, bundle: BundleBuilder<string, readonly ObjectBuilderLike[]>, options?: SyncBundleOptions): Promise<SyncBundleResult>;
33
+ /** What syncing the bundle would do: its pieces, its removals and the fingerprint to confirm them with. */
34
+ declare function previewBundleSync(transport: SyncTransport, bundle: BundleBuilder<string, readonly ObjectBuilderLike[]>): Promise<BundleSyncPreview>;
20
35
  /** `daily-stats` → `dailyStats`. Object names are kebab-case (enforced by the builder). */
21
36
  type CamelCase<S extends string> = S extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<CamelCase<Tail>>}` : S;
22
37
  type Attr<TBuilder> = keyof ExtractRecord<TBuilder> & string;
@@ -255,6 +270,7 @@ type AnyBundle = BundleBuilder<string, readonly ObjectBuilderLike[]>;
255
270
  /** The object builders of every bundle in a tuple: what the typed client infers from. */
256
271
  type ObjectsOfBundles<TBundles extends readonly AnyBundle[]> = TBundles[number]["objectBuilders"];
257
272
  type ContractSync = AppClient["bundles"]["sync"];
273
+ type ContractSyncPreview = AppClient["bundles"]["syncPreview"];
258
274
  /** `bundles.sync`, either way: from your bundle's builder, or the contract's call. */
259
275
  interface BundlesSync {
260
276
  /**
@@ -265,14 +281,22 @@ interface BundlesSync {
265
281
  /** The contract's call, with an artifact you built yourself. */
266
282
  (...args: Parameters<ContractSync>): ReturnType<ContractSync>;
267
283
  }
284
+ /** `bundles.syncPreview`, either way: from your bundle's builder, or the contract's call. */
285
+ interface BundlesSyncPreview {
286
+ /** Build `bundle` and preview its sync: its pieces, its removals and the fingerprint that confirms them. */
287
+ (bundle: AnyBundle): Promise<BundleSyncPreview>;
288
+ /** The contract's call, with an artifact you built yourself. */
289
+ (...args: Parameters<ContractSyncPreview>): ReturnType<ContractSyncPreview>;
290
+ }
268
291
  /**
269
292
  * The client: every operation of the contract at the root, by group and
270
293
  * verb (`decisions.list`, `users.get`, `files.upload`…), with your bundles'
271
294
  * objects beside them as typed queries (see {@link StandardsOf}).
272
295
  */
273
296
  type Standards = Omit<AppClient, "bundles"> & {
274
- readonly bundles: Omit<AppClient["bundles"], "sync"> & {
297
+ readonly bundles: Omit<AppClient["bundles"], "sync" | "syncPreview"> & {
275
298
  readonly sync: BundlesSync;
299
+ readonly syncPreview: BundlesSyncPreview;
276
300
  };
277
301
  /** Untyped access to an object the code does not declare (created at runtime). */
278
302
  from(objectName: string): UntypedRecordsQuery;
@@ -332,4 +356,4 @@ declare function createStandards<const TBundles extends readonly AnyBundle[]>(co
332
356
  bundles: TBundles;
333
357
  }): StandardsOf<ObjectsOfBundles<TBundles>>;
334
358
  declare function createStandards(config?: StandardsConfig): Standards;
335
- export { SyncBundleOptions as A, UntypedBuilder as C, UpdateManyResult as D, UpdateManyError as E, syncBundle as M, createRecordsQuery as O, RecordsQuery as S, UpdateManyEntry as T, RecordInput as _, ObjectsOfBundles as a, RecordsAggregateOptions as b, StandardsOf as c, CreateManyError as d, CreateManyResult as f, RecordCreateOptions as g, FetchResult as h, ObjectsOf as i, SyncTransport as j, CamelCase as k, StandardsTransport as l, DeleteManyResult as m, AnyBundle as n, Standards as o, DeleteManyError as p, BundlesSync as r, StandardsConfig as s, ActingStandards as t, createStandards as u, RecordUpdate as v, UntypedRecordsQuery as w, RecordsExportOptions as x, RecordUpdateOptions as y };
359
+ export { CamelCase as A, RecordsQuery as C, UpdateManyError as D, UpdateManyEntry as E, SyncTransport as M, previewBundleSync as N, UpdateManyResult as O, syncBundle as P, RecordsExportOptions as S, UntypedRecordsQuery as T, RecordCreateOptions as _, ObjectsOf as a, RecordUpdateOptions as b, StandardsConfig as c, createStandards as d, CreateManyError as f, FetchResult as g, DeleteManyResult as h, BundlesSyncPreview as i, SyncBundleOptions as j, createRecordsQuery as k, StandardsOf as l, DeleteManyError as m, AnyBundle as n, ObjectsOfBundles as o, CreateManyResult as p, BundlesSync as r, Standards as s, ActingStandards as t, StandardsTransport as u, RecordInput as v, UntypedBuilder as w, RecordsAggregateOptions as x, RecordUpdate as y };
@@ -0,0 +1,4 @@
1
+ /*! © 2025-2026 AND YOU CREATE SAS (RCS Paris 940 190 614). Proprietary — see LICENSE (Standards SDK License 1.0). */
2
+ import{d as e,f as t,h as n,i as r,m as i,o as a,t as o}from"./app-Cer-0oL4.mjs";import{AggregateValidationError as s,DuplicateError as c,RecordQuery as l,SCHEMA_ERROR_HTTP_STATUS as u,SchemaErrorCode as d,decodeRecordValues as f,encodeRecordValues as p,isPlainRecord as m}from"@standards/schema";import{buildOperationPath as h,bundlesOperations as g,callerOf as _,decodeOperationOutput as v,recordAccessOperations as y,recordOperationsOperations as b,recordsOperations as x}from"@standards/schema/api";async function readInstalled(e,t){try{return await e.call(g.get,{name:t})}catch(e){if(e instanceof n&&e.status===404)return null;throw e}}async function syncBundle(r,i,a={}){let o=await i.build(),{resolutions:s=[],fingerprint:c,confirmedRecords:l}=a,u=c!==void 0||l!==void 0?null:await readInstalled(r,o.name);if(u?.hash===o.hash&&u.label===o.label&&u.description===o.description&&u.uses.join(`
3
+ `)===o.uses.join(`
4
+ `))return{applied:!1,hash:o.hash,pendingRemovals:[]};let d={...o,...s.length>0?{resolutions:s}:{},...c===void 0?{}:{fingerprint:c},...l===void 0?{}:{confirmedRecords:l}};try{return await r.call(g.sync,{name:o.name,bundle:d})}catch(r){throw r instanceof n&&r.status===409?new e(r.status,r.message,r.code):r instanceof n&&r.status===400?new t(r.status,r.message,r.code):r}}async function previewBundleSync(e,t){let n=await t.build();return await e.call(g.syncPreview,{name:n.name,bundle:n})}function objectKeyOf(e){return e.replace(/-([a-z0-9])/g,(e,t)=>t.toUpperCase())}const S=/* @__PURE__ */ new Set([`from`,`bundles`,`contract`,`as`]);function assertObjectKeys(e){let t=/* @__PURE__ */ new Map;for(let n of e){if(n.includes(`--`)||n.endsWith(`-`))throw new i(`Object "${n}" has a doubled or trailing hyphen, which has no client key. Rename the object.`);let e=objectKeyOf(n);if(S.has(e))throw new i(`Object "${n}" maps to the client key "${e}", which is reserved. Rename the object.`);let r=t.get(e);if(r!==void 0&&r!==n)throw new i(`Objects "${r}" and "${n}" both map to the client key "${e}". Rename one of them.`);t.set(e,n)}}function assertObjectNames(e){let t=/* @__PURE__ */ new Set;for(let n of e){if(t.has(n))throw new c(`object`,n);t.add(n)}assertObjectKeys(e)}function readRecord(e,t){let{values:n,...r}=t;return m(n)?{...r,...f(e,n)}:t}var C=class RecordsQueryImpl extends l{constructor(e,t,n,r={object:t,combinator:`and`,rules:[],sorts:[]}){super(r),this.transport=e,this.objectName=t,this.definition=n}with(e){return new RecordsQueryImpl(this.transport,this.objectName,this.definition,{...this.state,...e})}body(){let e={};return this.state.search!==void 0&&(e.q=this.state.search),this.state.rules.length>0&&(e.filters={combinator:this.state.combinator,rules:this.state.rules}),this.state.sorts.length>0&&(e.sorts=this.state.sorts),this.state.limit!==void 0&&(e.limit=this.state.limit),this.state.offset!==void 0&&(e.offset=this.state.offset),e}revive(e){return readRecord(this.definition,e)}async export(e,t={}){if(!this.transport.postRaw)throw new i(`export() needs a transport with postRaw(path, body): Promise<Response>`);let{filters:n,sorts:r}=this.body(),{ids:a,locale:o,filename:s}=t;return await this.transport.postRaw(h(x.export,{objectName:this.objectName}),{q:this.state.search??``,...n?{filters:n}:{},...r?{sorts:r}:{},columns:e,...a?{ids:a}:{},...o?{locale:o}:{},timezone:t.timezone??Intl.DateTimeFormat().resolvedOptions().timeZone,...s?{filename:s}:{}})}async aggregate(e){if(this.state.search!==void 0)throw new s(d.AGGREGATE_SEARCH_UNSUPPORTED,`An aggregate cannot be narrowed by a search; use filters instead`);let t={...e,query:this.toDefinition(),timezone:e.timezone??Intl.DateTimeFormat().resolvedOptions().timeZone};return await this.transport.call(x.aggregate,{objectName:this.objectName,...t})}async fetchPage(){let e={objectName:this.objectName,...this.body()},t=this.state.search===void 0?await this.transport.call(x.list,e):await this.transport.call(x.search,e);return{records:t.data.map(e=>this.revive(e)),page:t.page}}async fetch(){let{records:e,page:t}=await this.fetchPage();return{records:e,total:t.total}}async all(){if(this.state.limit!==void 0&&this.state.limit<0)return(await this.fetch()).records;let e=this.state.limit??1/0,t=[],n=this.state.offset??0;for(;;){let r=Math.min(1e3,e-t.length);if(r<=0)return t;let{records:i,page:a}=await this.with({limit:r,offset:n}).fetchPage();if(t.push(...i),!a.hasMore)return t;let o=a.nextOffset??n+i.length;if(o<=n)return t;n=o}}async single(){let{records:e}=await this.limit(1).fetch();return e[0]??null}async get(e){let t=await this.transport.call(x.get,{objectName:this.objectName,id:e});return this.revive(t)}async create(e,{allowDraft:t,metadata:n}={}){let r={...t!==void 0&&{allowDraft:t},...n!==void 0&&{metadata:n}},i=await this.transport.call(x.create,{objectName:this.objectName,data:p(this.definition,e),...Object.keys(r).length>0&&{options:r}});return this.revive(i)}async update(e,t,{metadata:n}={}){let r=p(this.definition,t);if(n===void 0){let t=await this.transport.call(x.update,{objectName:this.objectName,id:e,values:r});return this.revive(t)}let{objectId:i}=await this.transport.call(x.get,{objectName:this.objectName,id:e}),{steps:o}=await this.transport.call(b.execute,{opId:crypto.randomUUID(),steps:[{kind:`record.set`,objectId:i,recordId:e,values:r,metadata:n}]}),[s]=o;if(s===void 0||s.status===`error`){let e=s?.code,t=e===void 0?500:u[e];throw a(t,JSON.stringify({message:s?.message,code:e}))}let c=v(x.get,s.record);return this.revive(c)}async delete(e){await this.transport.call(x.delete,{objectName:this.objectName,id:e})}async inChunks(e,t){for(let n=0;n<e.length;n+=100)await t(e.slice(n,n+100),n)}async createMany(e){let t={created:[],errors:[]};return await this.inChunks(e,async(e,n)=>{let r=await this.transport.call(x.bulkCreate,{objectName:this.objectName,records:e.map(e=>p(this.definition,e))});t.created.push(...r.created.map(e=>this.revive(e))),t.errors.push(...r.errors.map(e=>({...e,index:e.index+n})))}),t}async updateMany(e){let t={updated:[],errors:[]};return await this.inChunks(e,async e=>{let n=await this.transport.call(x.bulkUpdate,{objectName:this.objectName,updates:e.map(({id:e,data:t})=>({id:e,data:p(this.definition,t)}))});t.updated.push(...n.updated.map(e=>this.revive(e))),t.errors.push(...n.errors)}),t}async deleteMany(e){let t={deleted:[],errors:[]};return await this.inChunks(e,async e=>{let n=await this.transport.call(x.bulkDelete,{objectName:this.objectName,ids:e});t.deleted.push(...n.deleted),t.errors.push(...n.errors)}),t}async listAccess(e){return await this.transport.call(y.list,{objectName:this.objectName,recordId:e})}async grantAccess(e,t,n){return await this.transport.call(y.grant,{objectName:this.objectName,recordId:e,actorId:t,role:n})}async revokeAccess(e,t){return await this.transport.call(y.revoke,{objectName:this.objectName,recordId:e,actorId:t})}async clearAccess(e){return await this.transport.call(y.clear,{objectName:this.objectName,recordId:e})}};const w=/* @__PURE__ */ new WeakMap;function definitionOf(e){let t=w.get(e);if(t)return t;let n=e.build();return w.set(e,n),n}function createRecordsQuery(e,t){if(typeof t==`string`)return new C(e,t,null);let n=definitionOf(t);return new C(e,n.name,n)}function readEnvironment(){return typeof process>`u`||!process.env?{}:{baseUrl:process.env.STANDARDS_API_URL||void 0,apiKey:process.env.STANDARDS_API_KEY||void 0}}function resolveConfig(e){if(globalThis.window!==void 0){if(e.apiKey)throw new i(`createStandards received an apiKey in a browser context. API keys belong to server code only (Route Handlers, Server Components, scripts).`);if(e.baseUrl===void 0)throw new i(`createStandards needs an explicit baseUrl in a browser context: STANDARDS_API_URL and STANDARDS_API_KEY are never read from the environment there.`);return{...e,baseUrl:e.baseUrl,apiKey:``}}let t=readEnvironment(),n=e.baseUrl??t.baseUrl;if(n===void 0)throw new i(`createStandards needs a base URL: pass baseUrl or set the STANDARDS_API_URL environment variable.`);let r=e.apiKey??t.apiKey;if(r===void 0)throw new i(`createStandards needs an API key: pass apiKey or set the STANDARDS_API_KEY environment variable.`);return{...e,baseUrl:n,apiKey:r}}function createStandards(e={}){let{bundles:t=[],transport:n,...a}=e;if(n!==void 0&&Object.values(a).some(e=>e!==void 0))throw new i(`createStandards takes a transport or an HTTP connection (baseUrl, apiKey, tenantId, timeoutMs), not both.`);return buildStandards(n??r(resolveConfig(a)),t.flatMap(e=>e.objectBuilders))}function buildStandards(e,t){let n=o(e),sync=((t,r)=>isBundleBuilder(t)?syncBundle(e,t,r):n.bundles.sync(t,r)),syncPreview=((t,r)=>isBundleBuilder(t)?previewBundleSync(e,t):n.bundles.syncPreview(t,r)),r={...n,bundles:{...n.bundles,sync,syncPreview},from:t=>createRecordsQuery(e,t),contract:n},i=t.map(e=>definitionOf(e).name);assertObjectNames(i),t.forEach((t,n)=>{r[objectKeyOf(i[n])]=createRecordsQuery(e,t)});let a=e.withCaller?.bind(e);return a!==void 0&&(r.as=e=>buildStandards(a(_(e)),t)),r}function isBundleBuilder(e){return typeof e==`object`&&!!e&&`objectBuilders`in e&&typeof e.build==`function`}export{definitionOf as a,syncBundle as c,createRecordsQuery as i,createStandards as n,readRecord as o,resolveConfig as r,previewBundleSync as s,buildStandards as t};
@@ -0,0 +1,4 @@
1
+ /*! © 2025-2026 AND YOU CREATE SAS (RCS Paris 940 190 614). Proprietary — see LICENSE (Standards SDK License 1.0). */
2
+ const e=require("./app-BUHCJ8SR.js");let t=require("@standards/schema"),n=require("@standards/schema/api");async function readInstalled(t,r){try{return await t.call(n.bundlesOperations.get,{name:r})}catch(t){if(t instanceof e.h&&t.status===404)return null;throw t}}async function syncBundle(t,r,i={}){let a=await r.build(),{resolutions:o=[],fingerprint:s,confirmedRecords:c}=i,l=s!==void 0||c!==void 0?null:await readInstalled(t,a.name);if(l?.hash===a.hash&&l.label===a.label&&l.description===a.description&&l.uses.join(`
3
+ `)===a.uses.join(`
4
+ `))return{applied:!1,hash:a.hash,pendingRemovals:[]};let u={...a,...o.length>0?{resolutions:o}:{},...s===void 0?{}:{fingerprint:s},...c===void 0?{}:{confirmedRecords:c}};try{return await t.call(n.bundlesOperations.sync,{name:a.name,bundle:u})}catch(t){throw t instanceof e.h&&t.status===409?new e.d(t.status,t.message,t.code):t instanceof e.h&&t.status===400?new e.f(t.status,t.message,t.code):t}}async function previewBundleSync(e,t){let r=await t.build();return await e.call(n.bundlesOperations.syncPreview,{name:r.name,bundle:r})}function objectKeyOf(e){return e.replace(/-([a-z0-9])/g,(e,t)=>t.toUpperCase())}const r=/* @__PURE__ */ new Set([`from`,`bundles`,`contract`,`as`]);function assertObjectKeys(t){let n=/* @__PURE__ */ new Map;for(let i of t){if(i.includes(`--`)||i.endsWith(`-`))throw new e.m(`Object "${i}" has a doubled or trailing hyphen, which has no client key. Rename the object.`);let t=objectKeyOf(i);if(r.has(t))throw new e.m(`Object "${i}" maps to the client key "${t}", which is reserved. Rename the object.`);let a=n.get(t);if(a!==void 0&&a!==i)throw new e.m(`Objects "${a}" and "${i}" both map to the client key "${t}". Rename one of them.`);n.set(t,i)}}function assertObjectNames(e){let n=/* @__PURE__ */ new Set;for(let r of e){if(n.has(r))throw new t.DuplicateError(`object`,r);n.add(r)}assertObjectKeys(e)}function readRecord(e,n){let{values:r,...i}=n;return(0,t.isPlainRecord)(r)?{...i,...(0,t.decodeRecordValues)(e,r)}:n}var i=class RecordsQueryImpl extends t.RecordQuery{constructor(e,t,n,r={object:t,combinator:`and`,rules:[],sorts:[]}){super(r),this.transport=e,this.objectName=t,this.definition=n}with(e){return new RecordsQueryImpl(this.transport,this.objectName,this.definition,{...this.state,...e})}body(){let e={};return this.state.search!==void 0&&(e.q=this.state.search),this.state.rules.length>0&&(e.filters={combinator:this.state.combinator,rules:this.state.rules}),this.state.sorts.length>0&&(e.sorts=this.state.sorts),this.state.limit!==void 0&&(e.limit=this.state.limit),this.state.offset!==void 0&&(e.offset=this.state.offset),e}revive(e){return readRecord(this.definition,e)}async export(t,r={}){if(!this.transport.postRaw)throw new e.m(`export() needs a transport with postRaw(path, body): Promise<Response>`);let{filters:i,sorts:a}=this.body(),{ids:o,locale:s,filename:c}=r;return await this.transport.postRaw((0,n.buildOperationPath)(n.recordsOperations.export,{objectName:this.objectName}),{q:this.state.search??``,...i?{filters:i}:{},...a?{sorts:a}:{},columns:t,...o?{ids:o}:{},...s?{locale:s}:{},timezone:r.timezone??Intl.DateTimeFormat().resolvedOptions().timeZone,...c?{filename:c}:{}})}async aggregate(e){if(this.state.search!==void 0)throw new t.AggregateValidationError(t.SchemaErrorCode.AGGREGATE_SEARCH_UNSUPPORTED,`An aggregate cannot be narrowed by a search; use filters instead`);let r={...e,query:this.toDefinition(),timezone:e.timezone??Intl.DateTimeFormat().resolvedOptions().timeZone};return await this.transport.call(n.recordsOperations.aggregate,{objectName:this.objectName,...r})}async fetchPage(){let e={objectName:this.objectName,...this.body()},t=this.state.search===void 0?await this.transport.call(n.recordsOperations.list,e):await this.transport.call(n.recordsOperations.search,e);return{records:t.data.map(e=>this.revive(e)),page:t.page}}async fetch(){let{records:e,page:t}=await this.fetchPage();return{records:e,total:t.total}}async all(){if(this.state.limit!==void 0&&this.state.limit<0)return(await this.fetch()).records;let e=this.state.limit??1/0,t=[],n=this.state.offset??0;for(;;){let r=Math.min(1e3,e-t.length);if(r<=0)return t;let{records:i,page:a}=await this.with({limit:r,offset:n}).fetchPage();if(t.push(...i),!a.hasMore)return t;let o=a.nextOffset??n+i.length;if(o<=n)return t;n=o}}async single(){let{records:e}=await this.limit(1).fetch();return e[0]??null}async get(e){let t=await this.transport.call(n.recordsOperations.get,{objectName:this.objectName,id:e});return this.revive(t)}async create(e,{allowDraft:r,metadata:i}={}){let a={...r!==void 0&&{allowDraft:r},...i!==void 0&&{metadata:i}},o=await this.transport.call(n.recordsOperations.create,{objectName:this.objectName,data:(0,t.encodeRecordValues)(this.definition,e),...Object.keys(a).length>0&&{options:a}});return this.revive(o)}async update(r,i,{metadata:a}={}){let o=(0,t.encodeRecordValues)(this.definition,i);if(a===void 0){let e=await this.transport.call(n.recordsOperations.update,{objectName:this.objectName,id:r,values:o});return this.revive(e)}let{objectId:s}=await this.transport.call(n.recordsOperations.get,{objectName:this.objectName,id:r}),{steps:c}=await this.transport.call(n.recordOperationsOperations.execute,{opId:crypto.randomUUID(),steps:[{kind:`record.set`,objectId:s,recordId:r,values:o,metadata:a}]}),[l]=c;if(l===void 0||l.status===`error`){let n=l?.code,r=n===void 0?500:t.SCHEMA_ERROR_HTTP_STATUS[n];throw e.o(r,JSON.stringify({message:l?.message,code:n}))}let u=(0,n.decodeOperationOutput)(n.recordsOperations.get,l.record);return this.revive(u)}async delete(e){await this.transport.call(n.recordsOperations.delete,{objectName:this.objectName,id:e})}async inChunks(e,t){for(let n=0;n<e.length;n+=100)await t(e.slice(n,n+100),n)}async createMany(e){let r={created:[],errors:[]};return await this.inChunks(e,async(e,i)=>{let a=await this.transport.call(n.recordsOperations.bulkCreate,{objectName:this.objectName,records:e.map(e=>(0,t.encodeRecordValues)(this.definition,e))});r.created.push(...a.created.map(e=>this.revive(e))),r.errors.push(...a.errors.map(e=>({...e,index:e.index+i})))}),r}async updateMany(e){let r={updated:[],errors:[]};return await this.inChunks(e,async e=>{let i=await this.transport.call(n.recordsOperations.bulkUpdate,{objectName:this.objectName,updates:e.map(({id:e,data:n})=>({id:e,data:(0,t.encodeRecordValues)(this.definition,n)}))});r.updated.push(...i.updated.map(e=>this.revive(e))),r.errors.push(...i.errors)}),r}async deleteMany(e){let t={deleted:[],errors:[]};return await this.inChunks(e,async e=>{let r=await this.transport.call(n.recordsOperations.bulkDelete,{objectName:this.objectName,ids:e});t.deleted.push(...r.deleted),t.errors.push(...r.errors)}),t}async listAccess(e){return await this.transport.call(n.recordAccessOperations.list,{objectName:this.objectName,recordId:e})}async grantAccess(e,t,r){return await this.transport.call(n.recordAccessOperations.grant,{objectName:this.objectName,recordId:e,actorId:t,role:r})}async revokeAccess(e,t){return await this.transport.call(n.recordAccessOperations.revoke,{objectName:this.objectName,recordId:e,actorId:t})}async clearAccess(e){return await this.transport.call(n.recordAccessOperations.clear,{objectName:this.objectName,recordId:e})}};const a=/* @__PURE__ */ new WeakMap;function definitionOf(e){let t=a.get(e);if(t)return t;let n=e.build();return a.set(e,n),n}function createRecordsQuery(e,t){if(typeof t==`string`)return new i(e,t,null);let n=definitionOf(t);return new i(e,n.name,n)}function readEnvironment(){return typeof process>`u`||!process.env?{}:{baseUrl:process.env.STANDARDS_API_URL||void 0,apiKey:process.env.STANDARDS_API_KEY||void 0}}function resolveConfig(t){if(globalThis.window!==void 0){if(t.apiKey)throw new e.m(`createStandards received an apiKey in a browser context. API keys belong to server code only (Route Handlers, Server Components, scripts).`);if(t.baseUrl===void 0)throw new e.m(`createStandards needs an explicit baseUrl in a browser context: STANDARDS_API_URL and STANDARDS_API_KEY are never read from the environment there.`);return{...t,baseUrl:t.baseUrl,apiKey:``}}let n=readEnvironment(),r=t.baseUrl??n.baseUrl;if(r===void 0)throw new e.m(`createStandards needs a base URL: pass baseUrl or set the STANDARDS_API_URL environment variable.`);let i=t.apiKey??n.apiKey;if(i===void 0)throw new e.m(`createStandards needs an API key: pass apiKey or set the STANDARDS_API_KEY environment variable.`);return{...t,baseUrl:r,apiKey:i}}function createStandards(t={}){let{bundles:n=[],transport:r,...i}=t;if(r!==void 0&&Object.values(i).some(e=>e!==void 0))throw new e.m(`createStandards takes a transport or an HTTP connection (baseUrl, apiKey, tenantId, timeoutMs), not both.`);return buildStandards(r??e.i(resolveConfig(i)),n.flatMap(e=>e.objectBuilders))}function buildStandards(t,r){let i=e.t(t),sync=((e,n)=>isBundleBuilder(e)?syncBundle(t,e,n):i.bundles.sync(e,n)),syncPreview=((e,n)=>isBundleBuilder(e)?previewBundleSync(t,e):i.bundles.syncPreview(e,n)),a={...i,bundles:{...i.bundles,sync,syncPreview},from:e=>createRecordsQuery(t,e),contract:i},o=r.map(e=>definitionOf(e).name);assertObjectNames(o),r.forEach((e,n)=>{a[objectKeyOf(o[n])]=createRecordsQuery(t,e)});let s=t.withCaller?.bind(t);return s!==void 0&&(a.as=e=>buildStandards(s((0,n.callerOf)(e)),r)),a}function isBundleBuilder(e){return typeof e==`object`&&!!e&&`objectBuilders`in e&&typeof e.build==`function`}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return definitionOf}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return syncBundle}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return createRecordsQuery}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return createStandards}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return readRecord}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return resolveConfig}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return previewBundleSync}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return buildStandards}});
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- import { A as SyncBundleOptions, C as UntypedBuilder, D as UpdateManyResult, E as UpdateManyError, M as syncBundle, O as createRecordsQuery, S as RecordsQuery, T as UpdateManyEntry, _ as RecordInput, a as ObjectsOfBundles, b as RecordsAggregateOptions, c as StandardsOf, d as CreateManyError, f as CreateManyResult, g as RecordCreateOptions, h as FetchResult, i as ObjectsOf, j as SyncTransport, k as CamelCase, l as StandardsTransport, m as DeleteManyResult, n as AnyBundle, o as Standards, p as DeleteManyError, r as BundlesSync, s as StandardsConfig, t as ActingStandards, u as createStandards, v as RecordUpdate, w as UntypedRecordsQuery, x as RecordsExportOptions, y as RecordUpdateOptions } from "./create-standards-Drl7CgKx.mjs";
2
+ import { A as CamelCase, C as RecordsQuery, D as UpdateManyError, E as UpdateManyEntry, M as SyncTransport, N as previewBundleSync, O as UpdateManyResult, P as syncBundle, S as RecordsExportOptions, T as UntypedRecordsQuery, _ as RecordCreateOptions, a as ObjectsOf, b as RecordUpdateOptions, c as StandardsConfig, d as createStandards, f as CreateManyError, g as FetchResult, h as DeleteManyResult, i as BundlesSyncPreview, j as SyncBundleOptions, k as createRecordsQuery, l as StandardsOf, m as DeleteManyError, n as AnyBundle, o as ObjectsOfBundles, p as CreateManyResult, r as BundlesSync, s as Standards, t as ActingStandards, u as StandardsTransport, v as RecordInput, w as UntypedBuilder, x as RecordsAggregateOptions, y as RecordUpdate } from "./create-standards-DPw1bxv6.mjs";
3
3
  import { E as TransportConfig, F as StandardsConfigurationError, I as StandardsRequestError, M as BundleConflictError, N as BundleValidationError, P as StandardsAuthError, T as Transport, k as createTransport, x as MultipartRequestOptions } from "./app-t-7y8Oio.mjs";
4
4
  import { ActorType, Attribute, BUNDLE_NAME_PATTERN, BuiltBundle, BundleBuilder, BundlePiece, CollectionPage, CollectionResponse, ContentViewDefinition, DuplicateError, ExtractRecord, ExtractRecordInput, ExtractRecordInputStrict, ExtractRecordStrict, ExtractRecordUpdate, ExtractRecordUpdateStrict, FilterCombinator, FilterOperator, FilterRule, FilterState, ForbiddenError, InstalledBundleSummary, NotFoundError, ObjectBuilderLike, ObjectDefinition, RecordAccessRole, RecordAudience, RecordMetadata, SchemaError, SchemaErrorCode, SchemaSourceCurrencyRetype, SchemaSourcePhoneRetype, SchemaSourceRename, SchemaSourceResolution, SchemaSourceRetype, SortDirection, SortRule, SyncBundleResult, UsageBucket, UsageModality, UsageReport, UsageScope, ValidationError, ViewContentDefinition, ViewDeclaration, ViewerAccess, WalletState, assertBundleName, bundle, canonicalStringify, checkbox, content, currency, currentActor, date, detailView, document, formula, group, listView, location, multiselect, now, number, object, phone, query, relation, richtext, rollup, select, status, text, today, user } from "@standards/schema";
5
5
  import { ActorId, OperationCaller, encodePathSegment } from "@standards/schema/api";
@@ -32,4 +32,4 @@ export declare const standards: DefaultStandards;
32
32
  * never leave `/records/<object>/`.
33
33
  */
34
34
  export declare function recordsPath(objectName: string, ...segments: string[]): string;
35
- export { type ActingStandards, type ActorId, type ActorType, type AnyBundle, type Attribute, BUNDLE_NAME_PATTERN, type BuiltBundle, type BundleBuilder, BundleConflictError, type BundlePiece, BundleValidationError, type BundlesSync, type CamelCase, type CollectionPage, type CollectionResponse, type ContentViewDefinition, type CreateManyError, type CreateManyResult, type DefaultStandards, type DeleteManyError, type DeleteManyResult, DuplicateError, type ExtractRecord, type ExtractRecordInput, type ExtractRecordInputStrict, type ExtractRecordStrict, type ExtractRecordUpdate, type ExtractRecordUpdateStrict, type FetchResult, type FilterCombinator, type FilterOperator, type FilterRule, type FilterState, ForbiddenError, type InstalledBundleSummary, type MultipartRequestOptions, NotFoundError, type ObjectBuilderLike, type ObjectDefinition, type ObjectsOf, type ObjectsOfBundles, type OperationCaller, type RecordAccessRole, type RecordAudience, type RecordCreateOptions, type RecordInput, type RecordMetadata, type RecordUpdate, type RecordUpdateOptions, type RecordsAggregateOptions, type RecordsExportOptions, type RecordsQuery, type Register, SchemaError, SchemaErrorCode, type SchemaSourceCurrencyRetype, type SchemaSourcePhoneRetype, type SchemaSourceRename, type SchemaSourceResolution, type SchemaSourceRetype, type SortDirection, type SortRule, type Standards, StandardsAuthError, type StandardsConfig, StandardsConfigurationError, type StandardsOf, StandardsRequestError, type StandardsTransport, type SyncBundleOptions, type SyncBundleResult, type SyncTransport, type Transport, type TransportConfig, type UntypedBuilder, type UntypedRecordsQuery, type UpdateManyEntry, type UpdateManyError, type UpdateManyResult, type UsageBucket, type UsageModality, type UsageReport, type UsageScope, ValidationError, type ViewContentDefinition, type ViewDeclaration, type ViewerAccess, type WalletState, assertBundleName, bundle, canonicalStringify, checkbox, content, createRecordsQuery, createStandards, createTransport, currency, currentActor, date, detailView, document, encodePathSegment, formula, group, listView, location, multiselect, now, number, object, phone, query, relation, richtext, rollup, select, status, syncBundle, text, today, user };
35
+ export { type ActingStandards, type ActorId, type ActorType, type AnyBundle, type Attribute, BUNDLE_NAME_PATTERN, type BuiltBundle, type BundleBuilder, BundleConflictError, type BundlePiece, BundleValidationError, type BundlesSync, type BundlesSyncPreview, type CamelCase, type CollectionPage, type CollectionResponse, type ContentViewDefinition, type CreateManyError, type CreateManyResult, type DefaultStandards, type DeleteManyError, type DeleteManyResult, DuplicateError, type ExtractRecord, type ExtractRecordInput, type ExtractRecordInputStrict, type ExtractRecordStrict, type ExtractRecordUpdate, type ExtractRecordUpdateStrict, type FetchResult, type FilterCombinator, type FilterOperator, type FilterRule, type FilterState, ForbiddenError, type InstalledBundleSummary, type MultipartRequestOptions, NotFoundError, type ObjectBuilderLike, type ObjectDefinition, type ObjectsOf, type ObjectsOfBundles, type OperationCaller, type RecordAccessRole, type RecordAudience, type RecordCreateOptions, type RecordInput, type RecordMetadata, type RecordUpdate, type RecordUpdateOptions, type RecordsAggregateOptions, type RecordsExportOptions, type RecordsQuery, type Register, SchemaError, SchemaErrorCode, type SchemaSourceCurrencyRetype, type SchemaSourcePhoneRetype, type SchemaSourceRename, type SchemaSourceResolution, type SchemaSourceRetype, type SortDirection, type SortRule, type Standards, StandardsAuthError, type StandardsConfig, StandardsConfigurationError, type StandardsOf, StandardsRequestError, type StandardsTransport, type SyncBundleOptions, type SyncBundleResult, type SyncTransport, type Transport, type TransportConfig, type UntypedBuilder, type UntypedRecordsQuery, type UpdateManyEntry, type UpdateManyError, type UpdateManyResult, type UsageBucket, type UsageModality, type UsageReport, type UsageScope, ValidationError, type ViewContentDefinition, type ViewDeclaration, type ViewerAccess, type WalletState, assertBundleName, bundle, canonicalStringify, checkbox, content, createRecordsQuery, createStandards, createTransport, currency, currentActor, date, detailView, document, encodePathSegment, formula, group, listView, location, multiselect, now, number, object, phone, previewBundleSync, query, relation, richtext, rollup, select, status, syncBundle, text, today, user };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- import { A as SyncBundleOptions, C as UntypedBuilder, D as UpdateManyResult, E as UpdateManyError, M as syncBundle, O as createRecordsQuery, S as RecordsQuery, T as UpdateManyEntry, _ as RecordInput, a as ObjectsOfBundles, b as RecordsAggregateOptions, c as StandardsOf, d as CreateManyError, f as CreateManyResult, g as RecordCreateOptions, h as FetchResult, i as ObjectsOf, j as SyncTransport, k as CamelCase, l as StandardsTransport, m as DeleteManyResult, n as AnyBundle, o as Standards, p as DeleteManyError, r as BundlesSync, s as StandardsConfig, t as ActingStandards, u as createStandards, v as RecordUpdate, w as UntypedRecordsQuery, x as RecordsExportOptions, y as RecordUpdateOptions } from "./create-standards-BryXl7my.js";
2
+ import { A as CamelCase, C as RecordsQuery, D as UpdateManyError, E as UpdateManyEntry, M as SyncTransport, N as previewBundleSync, O as UpdateManyResult, P as syncBundle, S as RecordsExportOptions, T as UntypedRecordsQuery, _ as RecordCreateOptions, a as ObjectsOf, b as RecordUpdateOptions, c as StandardsConfig, d as createStandards, f as CreateManyError, g as FetchResult, h as DeleteManyResult, i as BundlesSyncPreview, j as SyncBundleOptions, k as createRecordsQuery, l as StandardsOf, m as DeleteManyError, n as AnyBundle, o as ObjectsOfBundles, p as CreateManyResult, r as BundlesSync, s as Standards, t as ActingStandards, u as StandardsTransport, v as RecordInput, w as UntypedBuilder, x as RecordsAggregateOptions, y as RecordUpdate } from "./create-standards-DZ6stJDK.js";
3
3
  import { E as TransportConfig, F as StandardsConfigurationError, I as StandardsRequestError, M as BundleConflictError, N as BundleValidationError, P as StandardsAuthError, T as Transport, k as createTransport, x as MultipartRequestOptions } from "./app-t-7y8Oio.js";
4
4
  import { ActorType, Attribute, BUNDLE_NAME_PATTERN, BuiltBundle, BundleBuilder, BundlePiece, CollectionPage, CollectionResponse, ContentViewDefinition, DuplicateError, ExtractRecord, ExtractRecordInput, ExtractRecordInputStrict, ExtractRecordStrict, ExtractRecordUpdate, ExtractRecordUpdateStrict, FilterCombinator, FilterOperator, FilterRule, FilterState, ForbiddenError, InstalledBundleSummary, NotFoundError, ObjectBuilderLike, ObjectDefinition, RecordAccessRole, RecordAudience, RecordMetadata, SchemaError, SchemaErrorCode, SchemaSourceCurrencyRetype, SchemaSourcePhoneRetype, SchemaSourceRename, SchemaSourceResolution, SchemaSourceRetype, SortDirection, SortRule, SyncBundleResult, UsageBucket, UsageModality, UsageReport, UsageScope, ValidationError, ViewContentDefinition, ViewDeclaration, ViewerAccess, WalletState, assertBundleName, bundle, canonicalStringify, checkbox, content, currency, currentActor, date, detailView, document, formula, group, listView, location, multiselect, now, number, object, phone, query, relation, richtext, rollup, select, status, text, today, user } from "@standards/schema";
5
5
  import { ActorId, OperationCaller, encodePathSegment } from "@standards/schema/api";
@@ -32,4 +32,4 @@ export declare const standards: DefaultStandards;
32
32
  * never leave `/records/<object>/`.
33
33
  */
34
34
  export declare function recordsPath(objectName: string, ...segments: string[]): string;
35
- export { type ActingStandards, type ActorId, type ActorType, type AnyBundle, type Attribute, BUNDLE_NAME_PATTERN, type BuiltBundle, type BundleBuilder, BundleConflictError, type BundlePiece, BundleValidationError, type BundlesSync, type CamelCase, type CollectionPage, type CollectionResponse, type ContentViewDefinition, type CreateManyError, type CreateManyResult, type DefaultStandards, type DeleteManyError, type DeleteManyResult, DuplicateError, type ExtractRecord, type ExtractRecordInput, type ExtractRecordInputStrict, type ExtractRecordStrict, type ExtractRecordUpdate, type ExtractRecordUpdateStrict, type FetchResult, type FilterCombinator, type FilterOperator, type FilterRule, type FilterState, ForbiddenError, type InstalledBundleSummary, type MultipartRequestOptions, NotFoundError, type ObjectBuilderLike, type ObjectDefinition, type ObjectsOf, type ObjectsOfBundles, type OperationCaller, type RecordAccessRole, type RecordAudience, type RecordCreateOptions, type RecordInput, type RecordMetadata, type RecordUpdate, type RecordUpdateOptions, type RecordsAggregateOptions, type RecordsExportOptions, type RecordsQuery, type Register, SchemaError, SchemaErrorCode, type SchemaSourceCurrencyRetype, type SchemaSourcePhoneRetype, type SchemaSourceRename, type SchemaSourceResolution, type SchemaSourceRetype, type SortDirection, type SortRule, type Standards, StandardsAuthError, type StandardsConfig, StandardsConfigurationError, type StandardsOf, StandardsRequestError, type StandardsTransport, type SyncBundleOptions, type SyncBundleResult, type SyncTransport, type Transport, type TransportConfig, type UntypedBuilder, type UntypedRecordsQuery, type UpdateManyEntry, type UpdateManyError, type UpdateManyResult, type UsageBucket, type UsageModality, type UsageReport, type UsageScope, ValidationError, type ViewContentDefinition, type ViewDeclaration, type ViewerAccess, type WalletState, assertBundleName, bundle, canonicalStringify, checkbox, content, createRecordsQuery, createStandards, createTransport, currency, currentActor, date, detailView, document, encodePathSegment, formula, group, listView, location, multiselect, now, number, object, phone, query, relation, richtext, rollup, select, status, syncBundle, text, today, user };
35
+ export { type ActingStandards, type ActorId, type ActorType, type AnyBundle, type Attribute, BUNDLE_NAME_PATTERN, type BuiltBundle, type BundleBuilder, BundleConflictError, type BundlePiece, BundleValidationError, type BundlesSync, type BundlesSyncPreview, type CamelCase, type CollectionPage, type CollectionResponse, type ContentViewDefinition, type CreateManyError, type CreateManyResult, type DefaultStandards, type DeleteManyError, type DeleteManyResult, DuplicateError, type ExtractRecord, type ExtractRecordInput, type ExtractRecordInputStrict, type ExtractRecordStrict, type ExtractRecordUpdate, type ExtractRecordUpdateStrict, type FetchResult, type FilterCombinator, type FilterOperator, type FilterRule, type FilterState, ForbiddenError, type InstalledBundleSummary, type MultipartRequestOptions, NotFoundError, type ObjectBuilderLike, type ObjectDefinition, type ObjectsOf, type ObjectsOfBundles, type OperationCaller, type RecordAccessRole, type RecordAudience, type RecordCreateOptions, type RecordInput, type RecordMetadata, type RecordUpdate, type RecordUpdateOptions, type RecordsAggregateOptions, type RecordsExportOptions, type RecordsQuery, type Register, SchemaError, SchemaErrorCode, type SchemaSourceCurrencyRetype, type SchemaSourcePhoneRetype, type SchemaSourceRename, type SchemaSourceResolution, type SchemaSourceRetype, type SortDirection, type SortRule, type Standards, StandardsAuthError, type StandardsConfig, StandardsConfigurationError, type StandardsOf, StandardsRequestError, type StandardsTransport, type SyncBundleOptions, type SyncBundleResult, type SyncTransport, type Transport, type TransportConfig, type UntypedBuilder, type UntypedRecordsQuery, type UpdateManyEntry, type UpdateManyError, type UpdateManyResult, type UsageBucket, type UsageModality, type UsageReport, type UsageScope, ValidationError, type ViewContentDefinition, type ViewDeclaration, type ViewerAccess, type WalletState, assertBundleName, bundle, canonicalStringify, checkbox, content, createRecordsQuery, createStandards, createTransport, currency, currentActor, date, detailView, document, encodePathSegment, formula, group, listView, location, multiselect, now, number, object, phone, previewBundleSync, query, relation, richtext, rollup, select, status, syncBundle, text, today, user };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! © 2025-2026 AND YOU CREATE SAS (RCS Paris 940 190 614). Proprietary — see LICENSE (Standards SDK License 1.0). */
2
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./create-standards-Lzg4-045.js"),t=require("./app-BUHCJ8SR.js");let n=require("@standards/schema/api"),r=require("@standards/schema");const i=/* @__PURE__ */ new WeakMap;let a;function resolved(){let r=(0,n.registeredOperationHost)();if(r!==void 0){let n=i.get(r);return n===void 0&&(n=e.t(t.n(r.host),r.objects),i.set(r,n)),n}if(a===void 0){let n;try{n=e.r({})}catch(e){throw e instanceof t.m?new t.m(`The default standards instance found no Standards host in this process (a server embedding Standards registers one at boot), so it calls the API over HTTP, and ${e.message}`):e}a=e.t(t.i(n),[])}return a}function asOverHttp(e){throw new t.m(`standards.as() acts in process only, in a server that embeds Standards: over HTTP every call acts as the API key's actor. Use a key of the actor you want instead.`)}const o=new Proxy({},{get(e,t){if(typeof t==`symbol`||t===`then`)return;let n=resolved();return t===`as`&&!(`as`in n)?asOverHttp:Reflect.get(n,t)},has:(e,t)=>Reflect.has(resolved(),t),ownKeys:()=>Reflect.ownKeys(resolved()),getOwnPropertyDescriptor(e,t){let n=Reflect.getOwnPropertyDescriptor(resolved(),t);return n===void 0?void 0:{...n,configurable:!0}}});Object.defineProperty(exports,"BUNDLE_NAME_PATTERN",{enumerable:!0,get:function(){return r.BUNDLE_NAME_PATTERN}}),exports.BundleConflictError=t.d,exports.BundleValidationError=t.f,Object.defineProperty(exports,"DuplicateError",{enumerable:!0,get:function(){return r.DuplicateError}}),Object.defineProperty(exports,"ForbiddenError",{enumerable:!0,get:function(){return r.ForbiddenError}}),Object.defineProperty(exports,"NotFoundError",{enumerable:!0,get:function(){return r.NotFoundError}}),Object.defineProperty(exports,"SchemaError",{enumerable:!0,get:function(){return r.SchemaError}}),Object.defineProperty(exports,"SchemaErrorCode",{enumerable:!0,get:function(){return r.SchemaErrorCode}}),exports.StandardsAuthError=t.p,exports.StandardsConfigurationError=t.m,exports.StandardsRequestError=t.h,Object.defineProperty(exports,"ValidationError",{enumerable:!0,get:function(){return r.ValidationError}}),Object.defineProperty(exports,"assertBundleName",{enumerable:!0,get:function(){return r.assertBundleName}}),Object.defineProperty(exports,"bundle",{enumerable:!0,get:function(){return r.bundle}}),Object.defineProperty(exports,"canonicalStringify",{enumerable:!0,get:function(){return r.canonicalStringify}}),Object.defineProperty(exports,"checkbox",{enumerable:!0,get:function(){return r.checkbox}}),Object.defineProperty(exports,"content",{enumerable:!0,get:function(){return r.content}}),exports.createRecordsQuery=e.i,exports.createStandards=e.n,exports.createTransport=t.i,Object.defineProperty(exports,"currency",{enumerable:!0,get:function(){return r.currency}}),Object.defineProperty(exports,"currentActor",{enumerable:!0,get:function(){return r.currentActor}}),Object.defineProperty(exports,"date",{enumerable:!0,get:function(){return r.date}}),Object.defineProperty(exports,"detailView",{enumerable:!0,get:function(){return r.detailView}}),Object.defineProperty(exports,"document",{enumerable:!0,get:function(){return r.document}}),Object.defineProperty(exports,"encodePathSegment",{enumerable:!0,get:function(){return n.encodePathSegment}}),Object.defineProperty(exports,"formula",{enumerable:!0,get:function(){return r.formula}}),Object.defineProperty(exports,"group",{enumerable:!0,get:function(){return r.group}}),Object.defineProperty(exports,"listView",{enumerable:!0,get:function(){return r.listView}}),Object.defineProperty(exports,"location",{enumerable:!0,get:function(){return r.location}}),Object.defineProperty(exports,"multiselect",{enumerable:!0,get:function(){return r.multiselect}}),Object.defineProperty(exports,"now",{enumerable:!0,get:function(){return r.now}}),Object.defineProperty(exports,"number",{enumerable:!0,get:function(){return r.number}}),Object.defineProperty(exports,"object",{enumerable:!0,get:function(){return r.object}}),Object.defineProperty(exports,"phone",{enumerable:!0,get:function(){return r.phone}}),Object.defineProperty(exports,"query",{enumerable:!0,get:function(){return r.query}}),exports.recordsPath=t.s,Object.defineProperty(exports,"relation",{enumerable:!0,get:function(){return r.relation}}),Object.defineProperty(exports,"richtext",{enumerable:!0,get:function(){return r.richtext}}),Object.defineProperty(exports,"rollup",{enumerable:!0,get:function(){return r.rollup}}),Object.defineProperty(exports,"select",{enumerable:!0,get:function(){return r.select}}),exports.standards=o,Object.defineProperty(exports,"status",{enumerable:!0,get:function(){return r.status}}),exports.syncBundle=e.s,Object.defineProperty(exports,"text",{enumerable:!0,get:function(){return r.text}}),Object.defineProperty(exports,"today",{enumerable:!0,get:function(){return r.today}}),Object.defineProperty(exports,"user",{enumerable:!0,get:function(){return r.user}});
2
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./create-standards-Drs4y84m.js"),t=require("./app-BUHCJ8SR.js");let n=require("@standards/schema/api"),r=require("@standards/schema");const i=/* @__PURE__ */ new WeakMap;let a;function resolved(){let r=(0,n.registeredOperationHost)();if(r!==void 0){let n=i.get(r);return n===void 0&&(n=e.t(t.n(r.host),r.objects),i.set(r,n)),n}if(a===void 0){let n;try{n=e.r({})}catch(e){throw e instanceof t.m?new t.m(`The default standards instance found no Standards host in this process (a server embedding Standards registers one at boot), so it calls the API over HTTP, and ${e.message}`):e}a=e.t(t.i(n),[])}return a}function asOverHttp(e){throw new t.m(`standards.as() acts in process only, in a server that embeds Standards: over HTTP every call acts as the API key's actor. Use a key of the actor you want instead.`)}const o=new Proxy({},{get(e,t){if(typeof t==`symbol`||t===`then`)return;let n=resolved();return t===`as`&&!(`as`in n)?asOverHttp:Reflect.get(n,t)},has:(e,t)=>Reflect.has(resolved(),t),ownKeys:()=>Reflect.ownKeys(resolved()),getOwnPropertyDescriptor(e,t){let n=Reflect.getOwnPropertyDescriptor(resolved(),t);return n===void 0?void 0:{...n,configurable:!0}}});Object.defineProperty(exports,"BUNDLE_NAME_PATTERN",{enumerable:!0,get:function(){return r.BUNDLE_NAME_PATTERN}}),exports.BundleConflictError=t.d,exports.BundleValidationError=t.f,Object.defineProperty(exports,"DuplicateError",{enumerable:!0,get:function(){return r.DuplicateError}}),Object.defineProperty(exports,"ForbiddenError",{enumerable:!0,get:function(){return r.ForbiddenError}}),Object.defineProperty(exports,"NotFoundError",{enumerable:!0,get:function(){return r.NotFoundError}}),Object.defineProperty(exports,"SchemaError",{enumerable:!0,get:function(){return r.SchemaError}}),Object.defineProperty(exports,"SchemaErrorCode",{enumerable:!0,get:function(){return r.SchemaErrorCode}}),exports.StandardsAuthError=t.p,exports.StandardsConfigurationError=t.m,exports.StandardsRequestError=t.h,Object.defineProperty(exports,"ValidationError",{enumerable:!0,get:function(){return r.ValidationError}}),Object.defineProperty(exports,"assertBundleName",{enumerable:!0,get:function(){return r.assertBundleName}}),Object.defineProperty(exports,"bundle",{enumerable:!0,get:function(){return r.bundle}}),Object.defineProperty(exports,"canonicalStringify",{enumerable:!0,get:function(){return r.canonicalStringify}}),Object.defineProperty(exports,"checkbox",{enumerable:!0,get:function(){return r.checkbox}}),Object.defineProperty(exports,"content",{enumerable:!0,get:function(){return r.content}}),exports.createRecordsQuery=e.i,exports.createStandards=e.n,exports.createTransport=t.i,Object.defineProperty(exports,"currency",{enumerable:!0,get:function(){return r.currency}}),Object.defineProperty(exports,"currentActor",{enumerable:!0,get:function(){return r.currentActor}}),Object.defineProperty(exports,"date",{enumerable:!0,get:function(){return r.date}}),Object.defineProperty(exports,"detailView",{enumerable:!0,get:function(){return r.detailView}}),Object.defineProperty(exports,"document",{enumerable:!0,get:function(){return r.document}}),Object.defineProperty(exports,"encodePathSegment",{enumerable:!0,get:function(){return n.encodePathSegment}}),Object.defineProperty(exports,"formula",{enumerable:!0,get:function(){return r.formula}}),Object.defineProperty(exports,"group",{enumerable:!0,get:function(){return r.group}}),Object.defineProperty(exports,"listView",{enumerable:!0,get:function(){return r.listView}}),Object.defineProperty(exports,"location",{enumerable:!0,get:function(){return r.location}}),Object.defineProperty(exports,"multiselect",{enumerable:!0,get:function(){return r.multiselect}}),Object.defineProperty(exports,"now",{enumerable:!0,get:function(){return r.now}}),Object.defineProperty(exports,"number",{enumerable:!0,get:function(){return r.number}}),Object.defineProperty(exports,"object",{enumerable:!0,get:function(){return r.object}}),Object.defineProperty(exports,"phone",{enumerable:!0,get:function(){return r.phone}}),exports.previewBundleSync=e.s,Object.defineProperty(exports,"query",{enumerable:!0,get:function(){return r.query}}),exports.recordsPath=t.s,Object.defineProperty(exports,"relation",{enumerable:!0,get:function(){return r.relation}}),Object.defineProperty(exports,"richtext",{enumerable:!0,get:function(){return r.richtext}}),Object.defineProperty(exports,"rollup",{enumerable:!0,get:function(){return r.rollup}}),Object.defineProperty(exports,"select",{enumerable:!0,get:function(){return r.select}}),exports.standards=o,Object.defineProperty(exports,"status",{enumerable:!0,get:function(){return r.status}}),exports.syncBundle=e.c,Object.defineProperty(exports,"text",{enumerable:!0,get:function(){return r.text}}),Object.defineProperty(exports,"today",{enumerable:!0,get:function(){return r.today}}),Object.defineProperty(exports,"user",{enumerable:!0,get:function(){return r.user}});
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! © 2025-2026 AND YOU CREATE SAS (RCS Paris 940 190 614). Proprietary — see LICENSE (Standards SDK License 1.0). */
2
- import{i as e,n as t,r as n,s as r,t as i}from"./create-standards-B9jNTqFf.mjs";import{d as a,f as o,h as s,i as c,m as l,n as u,p as d,s as f}from"./app-Cer-0oL4.mjs";import{BUNDLE_NAME_PATTERN as p,DuplicateError as m,ForbiddenError as h,NotFoundError as g,SchemaError as _,SchemaErrorCode as v,ValidationError as y,assertBundleName as b,bundle as x,canonicalStringify as S,checkbox as C,content as w,currency as T,currentActor as E,date as D,detailView as O,document as k,formula as A,group as j,listView as M,location as N,multiselect as P,now as F,number as I,object as L,phone as R,query as z,relation as B,richtext as V,rollup as H,select as U,status as W,text as G,today as K,user as q}from"@standards/schema";import{encodePathSegment as J,registeredOperationHost as Y}from"@standards/schema/api";const X=/* @__PURE__ */ new WeakMap;let Z;function resolved(){let e=Y();if(e!==void 0){let t=X.get(e);return t===void 0&&(t=i(u(e.host),e.objects),X.set(e,t)),t}if(Z===void 0){let e;try{e=n({})}catch(e){throw e instanceof l?new l(`The default standards instance found no Standards host in this process (a server embedding Standards registers one at boot), so it calls the API over HTTP, and ${e.message}`):e}Z=i(c(e),[])}return Z}function asOverHttp(e){throw new l(`standards.as() acts in process only, in a server that embeds Standards: over HTTP every call acts as the API key's actor. Use a key of the actor you want instead.`)}const Q=new Proxy({},{get(e,t){if(typeof t==`symbol`||t===`then`)return;let n=resolved();return t===`as`&&!(`as`in n)?asOverHttp:Reflect.get(n,t)},has:(e,t)=>Reflect.has(resolved(),t),ownKeys:()=>Reflect.ownKeys(resolved()),getOwnPropertyDescriptor(e,t){let n=Reflect.getOwnPropertyDescriptor(resolved(),t);return n===void 0?void 0:{...n,configurable:!0}}});export{p as BUNDLE_NAME_PATTERN,a as BundleConflictError,o as BundleValidationError,m as DuplicateError,h as ForbiddenError,g as NotFoundError,_ as SchemaError,v as SchemaErrorCode,d as StandardsAuthError,l as StandardsConfigurationError,s as StandardsRequestError,y as ValidationError,b as assertBundleName,x as bundle,S as canonicalStringify,C as checkbox,w as content,e as createRecordsQuery,t as createStandards,c as createTransport,T as currency,E as currentActor,D as date,O as detailView,k as document,J as encodePathSegment,A as formula,j as group,M as listView,N as location,P as multiselect,F as now,I as number,L as object,R as phone,z as query,f as recordsPath,B as relation,V as richtext,H as rollup,U as select,Q as standards,W as status,r as syncBundle,G as text,K as today,q as user};
2
+ import{c as e,i as t,n,r,s as i,t as a}from"./create-standards-Dq4tC8T6.mjs";import{d as o,f as s,h as c,i as l,m as u,n as d,p as f,s as p}from"./app-Cer-0oL4.mjs";import{BUNDLE_NAME_PATTERN as m,DuplicateError as h,ForbiddenError as g,NotFoundError as _,SchemaError as v,SchemaErrorCode as y,ValidationError as b,assertBundleName as x,bundle as S,canonicalStringify as C,checkbox as w,content as T,currency as E,currentActor as D,date as O,detailView as k,document as A,formula as j,group as M,listView as N,location as P,multiselect as F,now as I,number as L,object as R,phone as z,query as B,relation as V,richtext as H,rollup as U,select as W,status as G,text as K,today as q,user as J}from"@standards/schema";import{encodePathSegment as Y,registeredOperationHost as X}from"@standards/schema/api";const Z=/* @__PURE__ */ new WeakMap;let Q;function resolved(){let e=X();if(e!==void 0){let t=Z.get(e);return t===void 0&&(t=a(d(e.host),e.objects),Z.set(e,t)),t}if(Q===void 0){let e;try{e=r({})}catch(e){throw e instanceof u?new u(`The default standards instance found no Standards host in this process (a server embedding Standards registers one at boot), so it calls the API over HTTP, and ${e.message}`):e}Q=a(l(e),[])}return Q}function asOverHttp(e){throw new u(`standards.as() acts in process only, in a server that embeds Standards: over HTTP every call acts as the API key's actor. Use a key of the actor you want instead.`)}const $=new Proxy({},{get(e,t){if(typeof t==`symbol`||t===`then`)return;let n=resolved();return t===`as`&&!(`as`in n)?asOverHttp:Reflect.get(n,t)},has:(e,t)=>Reflect.has(resolved(),t),ownKeys:()=>Reflect.ownKeys(resolved()),getOwnPropertyDescriptor(e,t){let n=Reflect.getOwnPropertyDescriptor(resolved(),t);return n===void 0?void 0:{...n,configurable:!0}}});export{m as BUNDLE_NAME_PATTERN,o as BundleConflictError,s as BundleValidationError,h as DuplicateError,g as ForbiddenError,_ as NotFoundError,v as SchemaError,y as SchemaErrorCode,f as StandardsAuthError,u as StandardsConfigurationError,c as StandardsRequestError,b as ValidationError,x as assertBundleName,S as bundle,C as canonicalStringify,w as checkbox,T as content,t as createRecordsQuery,n as createStandards,l as createTransport,E as currency,D as currentActor,O as date,k as detailView,A as document,Y as encodePathSegment,j as formula,M as group,N as listView,P as location,F as multiselect,I as now,L as number,R as object,z as phone,i as previewBundleSync,B as query,p as recordsPath,V as relation,H as richtext,U as rollup,W as select,$ as standards,G as status,e as syncBundle,K as text,q as today,J as user};
@@ -1,5 +1,5 @@
1
1
 
2
- import { a as ObjectsOfBundles, c as StandardsOf, n as AnyBundle } from "./create-standards-Drl7CgKx.mjs";
2
+ import { l as StandardsOf, n as AnyBundle, o as ObjectsOfBundles } from "./create-standards-DPw1bxv6.mjs";
3
3
  import "./app-t-7y8Oio.mjs";
4
4
  import { ExtractRecord, ExtractRecordInputStrict, ObjectBuilderLike } from "@standards/schema";
5
5
  /**
package/dist/testing.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- import { a as ObjectsOfBundles, c as StandardsOf, n as AnyBundle } from "./create-standards-BryXl7my.js";
2
+ import { l as StandardsOf, n as AnyBundle, o as ObjectsOfBundles } from "./create-standards-DZ6stJDK.js";
3
3
  import "./app-t-7y8Oio.js";
4
4
  import { ExtractRecord, ExtractRecordInputStrict, ObjectBuilderLike } from "@standards/schema";
5
5
  /**
package/dist/testing.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! © 2025-2026 AND YOU CREATE SAS (RCS Paris 940 190 614). Proprietary — see LICENSE (Standards SDK License 1.0). */
2
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./create-standards-Lzg4-045.js"),t=require("./app-BUHCJ8SR.js");let n=require("@standards/schema"),r=require("@standards/schema/api");var UnsupportedFilterOperatorError=class extends Error{constructor(e,t){super(`The in-memory test workspace does not serve the "${e}" operator (on "${t}"). Test it against a real workspace.`),this.name=`UnsupportedFilterOperatorError`,this.operator=e}};const i=/* @__PURE__ */ new Set([`id`,`createdAt`,`updatedAt`]),a=/* @__PURE__ */ new Set([`createdAt`,`updatedAt`]),o=/* @__PURE__ */ new Set([`number`,`currency`]),s=/* @__PURE__ */ new Set([`select`,`status`]),c=/^\d{4}-\d{2}-\d{2}/,l=/^(\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]))(?:[T ]((?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d{1,6})?)?)(Z|[+-](?:0\d|1[0-4])(?::?[0-5]\d)?)?)?$/;function attributeValue(e,t){if(i.has(t))return e[t];let n=e.values[t];return typeof n==`object`&&n&&`value`in n&&!Array.isArray(n)?n.value:n}function isEmptyValue(e){return e==null||e===``||Array.isArray(e)&&e.length===0}function textOf(e){return e==null?null:e instanceof Date?e.toISOString():typeof e==`string`?e:JSON.stringify(e)}function members(e){return Array.isArray(e)?e.map(String):null}function dayOf(e){let t=textOf(e);if(t===null||!c.test(t))return null;let n=t.slice(0,10);return Number.isNaN(Date.parse(`${n}T00:00:00.000Z`))?null:n}const u=Date.parse(`0001-01-01T00:00:00Z`);function instantOf(e){let t=typeof e==`object`&&e&&`start`in e?e.start:e,n=typeof t==`string`?l.exec(t):null;if(!n)return null;let[,r=``,i=`00:00`,a=`Z`]=n;if(r.startsWith(`0000`))return null;let o=a===`Z`?`Z`:`${a.slice(0,3)}:${a.slice(3).replace(`:`,``)||`00`}`,s=Date.parse(`${r}T${i}${o}`);return Number.isNaN(s)||(/* @__PURE__ */ new Date(`${r}T00:00:00Z`)).toISOString().slice(0,10)!==r||s<u?null:s}function nextDay(e){let t=/* @__PURE__ */ new Date(`${e}T00:00:00.000Z`);return t.setUTCDate(t.getUTCDate()+1),t.toISOString().slice(0,10)}function isUnmodelledDate(e){if(e?.type!==`date`)return!1;let t=e;return t.endDate===!0||t.includeTime===!0}function isTimedDate(e){return e?.type===`date`&&e.includeTime===!0}function matchesDay(e,t,n,r){let i=dayOf(n);if(i===null)return!1;let a=textOf(t),o=nextDay(i),s=r?textOf(n)??i:i;switch(e){case`is`:return a!==null&&a>=s&&a<o;case`is_not`:return a===null||a<s||a>=o;case`greater_than`:return a!==null&&a>=o;case`greater_or_equal`:return a!==null&&a>=s;case`less_than`:return a!==null&&a<s;default:return a!==null&&a<o}}function compare(e,t,n){let r=textOf(e),i=textOf(t);if(r===null||i===null)return null;if(n){let e=Number(r),t=Number(i);return r===``||Number.isNaN(e)||Number.isNaN(t)?null:e-t}return r<i?-1:+(r>i)}function matchesRule(e,t,r){let i=r.attributes.find(e=>e.name===t.attribute)?.type,s=attributeValue(e,t.attribute),c=i!==void 0&&o.has(i),l=textOf(t.value),u=l===null?void 0:(0,n.foldText)(l),d=textOf(s),f=d===null?null:(0,n.foldText)(d);if((i===`date`||a.has(t.attribute))&&[`is`,`is_not`,`greater_than`,`greater_or_equal`,`less_than`,`less_or_equal`].includes(t.operator))return matchesDay(t.operator,s,t.value,a.has(t.attribute));switch(t.operator){case`is`:return i===`checkbox`||i===void 0&&typeof t.value==`boolean`?t.value===!0?s===!0:s!==!0:textOf(s)!==null&&textOf(s)===textOf(t.value);case`is_not`:return textOf(s)===null||textOf(s)!==textOf(t.value);case`contains`:return Array.isArray(s)?(Array.isArray(t.value)?t.value.map(String):[String(t.value)]).every(e=>s.map(String).includes(e)):f!==null&&u!==void 0&&f.includes(u);case`not_contains`:return s==null||!matchesRule(e,{...t,operator:`contains`},r);case`starts_with`:return f!==null&&u!==void 0&&f.startsWith(u);case`ends_with`:return f!==null&&u!==void 0&&f.endsWith(u);case`greater_than`:case`greater_or_equal`:case`less_than`:case`less_or_equal`:{let e=compare(s,t.value,c);return e===null?!1:t.operator===`greater_than`?e>0:t.operator===`greater_or_equal`?e>=0:t.operator===`less_than`?e<0:e<=0}case`is_empty`:return isEmptyValue(s);case`is_not_empty`:return!isEmptyValue(s);case`any_of`:{let e=members(t.value);return e===null||e.length===0||s==null?!1:Array.isArray(s)?s.some(t=>e.includes(String(t))):e.includes(textOf(s)??``)}case`none_of`:{let e=members(t.value);return e===null?!1:e.length===0||s==null?!0:Array.isArray(s)?!s.some(t=>e.includes(String(t))):!e.includes(textOf(s)??``)}default:throw new UnsupportedFilterOperatorError(t.operator,t.attribute)}}const d=/* @__PURE__ */ new Set([`is`,`is_not`,`contains`,`not_contains`,`starts_with`,`ends_with`,`greater_than`,`greater_or_equal`,`less_than`,`less_or_equal`,`is_empty`,`is_not_empty`,`any_of`,`none_of`]);function assertServedOperators(e,t){for(let n of e?.rules??[])if(!d.has(n.operator)||n.attribute.startsWith(`metadata.`)||isUnmodelledDate(t.attributes.find(e=>e.name===n.attribute))&&n.operator!==`is_empty`&&n.operator!==`is_not_empty`)throw new UnsupportedFilterOperatorError(n.operator,n.attribute)}function matchesFilters(e,t,n){let r=t?.rules??[];if(r.length===0)return!0;let i=r.map(t=>matchesRule(e,t,n));return t?.combinator===`or`?i.some(Boolean):i.every(Boolean)}function matchesSearch(e,t){let n=t.trim().toLowerCase();return n===``||Object.values(e.values).some(e=>(Array.isArray(e)?e:[e]).some(e=>typeof e==`string`&&e.toLowerCase().includes(n)))}function sortKey(e,t,n){let r=attributeValue(e,t),i=n.attributes.find(e=>e.name===t);if(i&&s.has(i.type)){let e=(i.options??[]).findIndex(e=>e.value===r);return{position:e===-1?null:e,value:r}}return r}function isOptionKey(e){return typeof e==`object`&&!!e&&`position`in e}function compareOptionKeys(e,t,n){let r=n===`desc`?-1:1;return e.position!==null&&t.position!==null?r*(e.position-t.position):e.position!==null||t.position!==null?e.position===null?1:-1:r*(compare(e.value,t.value,!1)??0)}function compareInstants(e,t,n){let r=instantOf(e.values[n.attribute]),i=instantOf(t.values[n.attribute]);return r===i?0:r===null||i===null?r===null?1:-1:n.direction===`desc`?i-r:r-i}function compareRecords(e,t){let n=e&&e.length>0?[...e]:[{attribute:`createdAt`,direction:`desc`}];return n.some(e=>e.attribute===`id`)||n.push({attribute:`id`,direction:`asc`}),(e,r)=>{for(let i of n){let n=t.attributes.find(e=>e.name===i.attribute),a=n?.type;if(isTimedDate(n)){let t=compareInstants(e,r,i);if(t!==0)return t;continue}let s=sortKey(e,i.attribute,t),c=sortKey(r,i.attribute,t),l=isOptionKey(s)?s.value:s,u=isOptionKey(c)?c.value:c,d=textOf(l)===null,f=textOf(u)===null;if(d||f){if(d&&f)continue;return d?1:-1}if(isOptionKey(s)&&isOptionKey(c)){let e=compareOptionKeys(s,c,i.direction);if(e!==0)return e;continue}let p=compare(s,c,a!==void 0&&o.has(a))??0;if(p!==0)return i.direction===`desc`?-p:p}return 0}}const f=`SCHEMA_RECORD_NOT_FOUND`,p=`SCHEMA_VALIDATION_FAILED`,readNotFound=e=>`Record "${e}" not found.`,writeNotFound=e=>`Record with id "${e}" not found`,m=[`id`,`createdAt`,`updatedAt`];function withSystemAttributes(e){return{...e,attributes:[...e.attributes,...(0,n.getObjectSystemAttributes)(e)]}}function withoutSystemKeys(e){let t={...e};for(let e of m)delete t[e];return t}function boundOf(e,n,r){if(e==null)return r;if(typeof e!=`number`||!Number.isSafeInteger(e)||e<0)throw new t.h(400,`${n} must be a non-negative integer`);return e}function errorFor(e,n,r){return e===401||e===403?new t.p(e,n,r):new t.h(e,n,r)}function asTheServerValidates(e){try{e()}catch(e){throw e instanceof n.ValidationError?new t.h(400,e.message,e.code):e}}function notServed(e,n){return new t.h(501,`The in-memory test workspace does not serve ${e} ${n}: only the records API is in memory.`)}function isoOf(e,t){return e===void 0?t:e instanceof Date?e.toISOString():new Date(e).toISOString()}function wire(e){return JSON.parse(JSON.stringify(e))}function createInMemoryApi(i){let a=/* @__PURE__ */ new Map;for(let t of i.builders){let n=e.a(t);a.set(n.name,n)}let o=new Map([...a.keys()].map(e=>[e,[]])),s=/* @__PURE__ */ new Set,c=null,l=0,u=1;function now(){return l=Math.max(Date.now(),l+1),new Date(l).toISOString()}function newId(){let e;do e=`00000000-0000-4000-8000-${(u++).toString(16).padStart(12,`0`)}`;while(s.has(e));return e}function objectOf(e){let n=a.get(e),r=o.get(e);if(!(n&&r))throw new t.h(404,`Object "${e}" not found. Make sure the object exists and you have access to it.`);return{definition:n,records:r}}function insert(e,t){let{records:n}=objectOf(e),{id:r,createdAt:i,updatedAt:a,...o}=t,c=now(),l={id:r??newId(),values:wire(o),createdAt:isoOf(i,c),updatedAt:isoOf(a,isoOf(i,c)),visibility:`workspace`,ownedBy:null,metadata:{},objectId:objectOf(e).definition.id??e,label:``,parentId:null,ancestorIds:[],trashedWithRecordId:null,schemaVersion:1};return n.push(l),s.add(l.id),l}function find(e,n){let r=objectOf(e).records.find(e=>e.id===n);if(!r)throw new t.h(404,readNotFound(n),f);return r}function requireWritable(e,n){if(!objectOf(e).records.some(e=>e.id===n))throw new t.h(404,writeNotFound(n),f)}function update(e,n,r){let i=objectOf(e).records.find(e=>e.id===n);if(!i)throw new t.h(404,writeNotFound(n),f);return Object.assign(i.values,withoutSystemKeys(r)),i.updatedAt=now(),i}function remove(e,n){let{records:r}=objectOf(e),i=r.findIndex(e=>e.id===n);if(i===-1)throw new t.h(404,writeNotFound(n),f);r.splice(i,1)}function list(e,t,r){let{definition:i,records:a}=objectOf(e);for(let e of t.filters?.rules??[])asTheServerValidates(()=>(0,n.validateQualifiedRule)(structuredClone(e),{attributes:i.attributes}));assertServedOperators(t.filters,i);let o=Math.min(boundOf(t.limit,`limit`,20),1e3),s=boundOf(t.offset,`offset`,0);if(o===0)return{data:[],page:{hasMore:!1,total:null,countMode:`none`}};let c=r?t.q:void 0,l=a.filter(e=>matchesFilters(e,t.filters,i)).filter(e=>c===void 0||matchesSearch(e,c)).sort(compareRecords(t.sorts,i)),u=l.slice(s,s+o);return{data:u,page:{hasMore:s+u.length<l.length,total:null,countMode:`none`}}}function bulk(e,r,i){let a=i.records??i.updates??i.ids;if(!Array.isArray(a)||a.length>100)throw new t.h(400,`A bulk request carries at most 100 items.`);let o=withSystemAttributes(objectOf(e).definition);if(r===`bulk-create`){let r=[],i=[];for(let[s,c]of a.entries())if(!(0,n.isPlainRecord)(c))i.push({index:s,error:`Record data must be an object`});else try{asTheServerValidates(()=>(0,n.rejectUnknownAttributesOrThrow)(o,c)),r.push(insert(e,withoutSystemKeys(c)))}catch(e){if(!(e instanceof t.h))throw e;i.push({index:s,error:e.message})}return{created:r,errors:i}}if(r===`bulk-update`){let r=[],i=[];for(let{id:s,data:c}of a)try{if(!(0,n.isPlainRecord)(c))throw new t.h(400,`Update data must be an object`,p);requireWritable(e,s),asTheServerValidates(()=>(0,n.rejectUnknownAttributesOrThrow)(o,c)),r.push(update(e,s,c))}catch(e){if(!(e instanceof t.h))throw e;i.push({id:s,error:e.message,code:e.code??p})}return{updated:r,errors:i}}let s=[],c=[];for(let t of a)try{remove(e,t),s.push(t)}catch{c.push({id:t,error:writeNotFound(t),code:f})}return{deleted:s,errors:c}}function operation(e,r,i){let o=Array.isArray(i.steps)?i.steps:[],[s]=o;if(o.length!==1||!(0,n.isPlainRecord)(s)||s.kind!==`record.set`)throw notServed(e,r);let c=String(s.recordId),l=(0,n.isPlainRecord)(s.values)?s.values:{},u=[...a].find(([e,t])=>(t.id??e)===s.objectId)?.[0],answer=e=>({opId:i.opId,steps:[e],inverse:null});if(u===void 0||!objectOf(u).records.some(e=>e.id===c))return answer({status:`error`,recordId:c,code:f});try{asTheServerValidates(()=>(0,n.rejectUnknownAttributesOrThrow)(withSystemAttributes(objectOf(u).definition),l))}catch(e){if(!(e instanceof t.h))throw e;let n=e.code??p;return answer({status:`error`,recordId:c,code:n,...n===p&&{message:e.message}})}return answer({status:`applied`,record:update(u,c,l)})}function route(e,r,i){let[a,o,s,...c]=r.replace(/^\/+/,``).split(`/`);if(e===`POST`&&a===`operations`&&o===void 0)return operation(e,r,(0,n.isPlainRecord)(i)?i:{});if(a!==`records`||o===void 0||c.length>0)throw notServed(e,r);let l=decodeURIComponent(o),u=s===void 0?void 0:decodeURIComponent(s),d=(0,n.isPlainRecord)(i)?i:{};if(e===`POST`&&u===void 0){let e=(0,n.isPlainRecord)(d.data)?d.data:{};return asTheServerValidates(()=>(0,n.rejectUnknownAttributesOrThrow)(withSystemAttributes(objectOf(l).definition),e)),insert(l,withoutSystemKeys(e))}if(e===`POST`&&(u===`list`||u===`search`))return list(l,d,u===`search`);if(e===`POST`&&u?.startsWith(`bulk-`))return bulk(l,u,d);if(u===void 0)throw notServed(e,r);if(e===`GET`)return find(l,u);if(e===`PUT`||e===`PATCH`){if(Object.keys(d).length===0)throw new t.h(400,`Request body cannot be empty`);return requireWritable(l,u),asTheServerValidates(()=>(0,n.rejectUnknownAttributesOrThrow)(withSystemAttributes(objectOf(l).definition),d)),update(l,u,d)}if(e===`DELETE`)return remove(l,u),null;throw notServed(e,r)}function request(e,t,n){return Promise.resolve().then(()=>(takeFailure(),wire(route(e,t,n===void 0?void 0:wire(n)))))}function takeFailure(){if(c){let{status:e,failure:t}=c;throw c=null,errorFor(e,t.message??`Request failed with status ${e}`,t.code)}}let d={call:(e,t)=>Promise.resolve().then(()=>{let{path:n,body:i}=(0,r.splitOperationInput)(e,t??{});return request(e.method,n,i).then(t=>(0,r.decodeOperationOutput)(e,t??null))}),stream:(e,t)=>Promise.resolve().then(()=>{takeFailure();let{path:n}=(0,r.splitOperationInput)(e,t??{});throw notServed(e.method,n)}),get:e=>request(`GET`,e),post:(e,t)=>request(`POST`,e,t),patch:(e,t)=>request(`PATCH`,e,t),put:(e,t)=>request(`PUT`,e,t),delete:e=>request(`DELETE`,e),getText:e=>Promise.resolve().then(()=>{throw takeFailure(),notServed(`GET`,e)}),postRaw:e=>Promise.resolve().then(()=>{throw takeFailure(),notServed(`POST`,e)}),postMultipart:e=>Promise.resolve().then(()=>{throw takeFailure(),notServed(`POST`,e)})};return{transport:d,get:d.get,post:d.post,definitionOf:e=>objectOf(e).definition,seed:(e,t)=>t.map(t=>insert(e,t)),records:e=>objectOf(e).records,failNextRequestWith(e,t={}){c={status:e,failure:t}}}}function createTestStandards(t){let n=t.bundles.flatMap(e=>e.objectBuilders),i=createInMemoryApi({builders:n}),flatten=(t,n)=>e.o(i.definitionOf(t),(0,r.decodeOperationOutput)(r.recordsOperations.get,JSON.parse(JSON.stringify(n))));return{db:e.t(i.transport,n),seed:(e,t)=>i.seed(e,t).map(t=>flatten(e,t)),records:e=>i.records(e).map(t=>flatten(e,t)),failNextRequestWith:(e,t)=>i.failNextRequestWith(e,t)}}exports.UnsupportedFilterOperatorError=UnsupportedFilterOperatorError,exports.createTestStandards=createTestStandards;
2
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./create-standards-Drs4y84m.js"),t=require("./app-BUHCJ8SR.js");let n=require("@standards/schema"),r=require("@standards/schema/api");var UnsupportedFilterOperatorError=class extends Error{constructor(e,t){super(`The in-memory test workspace does not serve the "${e}" operator (on "${t}"). Test it against a real workspace.`),this.name=`UnsupportedFilterOperatorError`,this.operator=e}};const i=/* @__PURE__ */ new Set([`id`,`createdAt`,`updatedAt`]),a=/* @__PURE__ */ new Set([`createdAt`,`updatedAt`]),o=/* @__PURE__ */ new Set([`number`,`currency`]),s=/* @__PURE__ */ new Set([`select`,`status`]),c=/^\d{4}-\d{2}-\d{2}/,l=/^(\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]))(?:[T ]((?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d{1,6})?)?)(Z|[+-](?:0\d|1[0-4])(?::?[0-5]\d)?)?)?$/;function attributeValue(e,t){if(i.has(t))return e[t];let n=e.values[t];return typeof n==`object`&&n&&`value`in n&&!Array.isArray(n)?n.value:n}function isEmptyValue(e){return e==null||e===``||Array.isArray(e)&&e.length===0}function textOf(e){return e==null?null:e instanceof Date?e.toISOString():typeof e==`string`?e:JSON.stringify(e)}function members(e){return Array.isArray(e)?e.map(String):null}function dayOf(e){let t=textOf(e);if(t===null||!c.test(t))return null;let n=t.slice(0,10);return Number.isNaN(Date.parse(`${n}T00:00:00.000Z`))?null:n}const u=Date.parse(`0001-01-01T00:00:00Z`);function instantOf(e){let t=typeof e==`object`&&e&&`start`in e?e.start:e,n=typeof t==`string`?l.exec(t):null;if(!n)return null;let[,r=``,i=`00:00`,a=`Z`]=n;if(r.startsWith(`0000`))return null;let o=a===`Z`?`Z`:`${a.slice(0,3)}:${a.slice(3).replace(`:`,``)||`00`}`,s=Date.parse(`${r}T${i}${o}`);return Number.isNaN(s)||(/* @__PURE__ */ new Date(`${r}T00:00:00Z`)).toISOString().slice(0,10)!==r||s<u?null:s}function nextDay(e){let t=/* @__PURE__ */ new Date(`${e}T00:00:00.000Z`);return t.setUTCDate(t.getUTCDate()+1),t.toISOString().slice(0,10)}function isUnmodelledDate(e){if(e?.type!==`date`)return!1;let t=e;return t.endDate===!0||t.includeTime===!0}function isTimedDate(e){return e?.type===`date`&&e.includeTime===!0}function matchesDay(e,t,n,r){let i=dayOf(n);if(i===null)return!1;let a=textOf(t),o=nextDay(i),s=r?textOf(n)??i:i;switch(e){case`is`:return a!==null&&a>=s&&a<o;case`is_not`:return a===null||a<s||a>=o;case`greater_than`:return a!==null&&a>=o;case`greater_or_equal`:return a!==null&&a>=s;case`less_than`:return a!==null&&a<s;default:return a!==null&&a<o}}function compare(e,t,n){let r=textOf(e),i=textOf(t);if(r===null||i===null)return null;if(n){let e=Number(r),t=Number(i);return r===``||Number.isNaN(e)||Number.isNaN(t)?null:e-t}return r<i?-1:+(r>i)}function matchesRule(e,t,r){let i=r.attributes.find(e=>e.name===t.attribute)?.type,s=attributeValue(e,t.attribute),c=i!==void 0&&o.has(i),l=textOf(t.value),u=l===null?void 0:(0,n.foldText)(l),d=textOf(s),f=d===null?null:(0,n.foldText)(d);if((i===`date`||a.has(t.attribute))&&[`is`,`is_not`,`greater_than`,`greater_or_equal`,`less_than`,`less_or_equal`].includes(t.operator))return matchesDay(t.operator,s,t.value,a.has(t.attribute));switch(t.operator){case`is`:return i===`checkbox`||i===void 0&&typeof t.value==`boolean`?t.value===!0?s===!0:s!==!0:textOf(s)!==null&&textOf(s)===textOf(t.value);case`is_not`:return textOf(s)===null||textOf(s)!==textOf(t.value);case`contains`:return Array.isArray(s)?(Array.isArray(t.value)?t.value.map(String):[String(t.value)]).every(e=>s.map(String).includes(e)):f!==null&&u!==void 0&&f.includes(u);case`not_contains`:return s==null||!matchesRule(e,{...t,operator:`contains`},r);case`starts_with`:return f!==null&&u!==void 0&&f.startsWith(u);case`ends_with`:return f!==null&&u!==void 0&&f.endsWith(u);case`greater_than`:case`greater_or_equal`:case`less_than`:case`less_or_equal`:{let e=compare(s,t.value,c);return e===null?!1:t.operator===`greater_than`?e>0:t.operator===`greater_or_equal`?e>=0:t.operator===`less_than`?e<0:e<=0}case`is_empty`:return isEmptyValue(s);case`is_not_empty`:return!isEmptyValue(s);case`any_of`:{let e=members(t.value);return e===null||e.length===0||s==null?!1:Array.isArray(s)?s.some(t=>e.includes(String(t))):e.includes(textOf(s)??``)}case`none_of`:{let e=members(t.value);return e===null?!1:e.length===0||s==null?!0:Array.isArray(s)?!s.some(t=>e.includes(String(t))):!e.includes(textOf(s)??``)}default:throw new UnsupportedFilterOperatorError(t.operator,t.attribute)}}const d=/* @__PURE__ */ new Set([`is`,`is_not`,`contains`,`not_contains`,`starts_with`,`ends_with`,`greater_than`,`greater_or_equal`,`less_than`,`less_or_equal`,`is_empty`,`is_not_empty`,`any_of`,`none_of`]);function assertServedOperators(e,t){for(let n of e?.rules??[])if(!d.has(n.operator)||n.attribute.startsWith(`metadata.`)||isUnmodelledDate(t.attributes.find(e=>e.name===n.attribute))&&n.operator!==`is_empty`&&n.operator!==`is_not_empty`)throw new UnsupportedFilterOperatorError(n.operator,n.attribute)}function matchesFilters(e,t,n){let r=t?.rules??[];if(r.length===0)return!0;let i=r.map(t=>matchesRule(e,t,n));return t?.combinator===`or`?i.some(Boolean):i.every(Boolean)}function matchesSearch(e,t){let n=t.trim().toLowerCase();return n===``||Object.values(e.values).some(e=>(Array.isArray(e)?e:[e]).some(e=>typeof e==`string`&&e.toLowerCase().includes(n)))}function sortKey(e,t,n){let r=attributeValue(e,t),i=n.attributes.find(e=>e.name===t);if(i&&s.has(i.type)){let e=(i.options??[]).findIndex(e=>e.value===r);return{position:e===-1?null:e,value:r}}return r}function isOptionKey(e){return typeof e==`object`&&!!e&&`position`in e}function compareOptionKeys(e,t,n){let r=n===`desc`?-1:1;return e.position!==null&&t.position!==null?r*(e.position-t.position):e.position!==null||t.position!==null?e.position===null?1:-1:r*(compare(e.value,t.value,!1)??0)}function compareInstants(e,t,n){let r=instantOf(e.values[n.attribute]),i=instantOf(t.values[n.attribute]);return r===i?0:r===null||i===null?r===null?1:-1:n.direction===`desc`?i-r:r-i}function compareRecords(e,t){let n=e&&e.length>0?[...e]:[{attribute:`createdAt`,direction:`desc`}];return n.some(e=>e.attribute===`id`)||n.push({attribute:`id`,direction:`asc`}),(e,r)=>{for(let i of n){let n=t.attributes.find(e=>e.name===i.attribute),a=n?.type;if(isTimedDate(n)){let t=compareInstants(e,r,i);if(t!==0)return t;continue}let s=sortKey(e,i.attribute,t),c=sortKey(r,i.attribute,t),l=isOptionKey(s)?s.value:s,u=isOptionKey(c)?c.value:c,d=textOf(l)===null,f=textOf(u)===null;if(d||f){if(d&&f)continue;return d?1:-1}if(isOptionKey(s)&&isOptionKey(c)){let e=compareOptionKeys(s,c,i.direction);if(e!==0)return e;continue}let p=compare(s,c,a!==void 0&&o.has(a))??0;if(p!==0)return i.direction===`desc`?-p:p}return 0}}const f=`SCHEMA_RECORD_NOT_FOUND`,p=`SCHEMA_VALIDATION_FAILED`,readNotFound=e=>`Record "${e}" not found.`,writeNotFound=e=>`Record with id "${e}" not found`,m=[`id`,`createdAt`,`updatedAt`];function withSystemAttributes(e){return{...e,attributes:[...e.attributes,...(0,n.getObjectSystemAttributes)(e)]}}function withoutSystemKeys(e){let t={...e};for(let e of m)delete t[e];return t}function boundOf(e,n,r){if(e==null)return r;if(typeof e!=`number`||!Number.isSafeInteger(e)||e<0)throw new t.h(400,`${n} must be a non-negative integer`);return e}function errorFor(e,n,r){return e===401||e===403?new t.p(e,n,r):new t.h(e,n,r)}function asTheServerValidates(e){try{e()}catch(e){throw e instanceof n.ValidationError?new t.h(400,e.message,e.code):e}}function notServed(e,n){return new t.h(501,`The in-memory test workspace does not serve ${e} ${n}: only the records API is in memory.`)}function isoOf(e,t){return e===void 0?t:e instanceof Date?e.toISOString():new Date(e).toISOString()}function wire(e){return JSON.parse(JSON.stringify(e))}function createInMemoryApi(i){let a=/* @__PURE__ */ new Map;for(let t of i.builders){let n=e.a(t);a.set(n.name,n)}let o=new Map([...a.keys()].map(e=>[e,[]])),s=/* @__PURE__ */ new Set,c=null,l=0,u=1;function now(){return l=Math.max(Date.now(),l+1),new Date(l).toISOString()}function newId(){let e;do e=`00000000-0000-4000-8000-${(u++).toString(16).padStart(12,`0`)}`;while(s.has(e));return e}function objectOf(e){let n=a.get(e),r=o.get(e);if(!(n&&r))throw new t.h(404,`Object "${e}" not found. Make sure the object exists and you have access to it.`);return{definition:n,records:r}}function insert(e,t){let{records:n}=objectOf(e),{id:r,createdAt:i,updatedAt:a,...o}=t,c=now(),l={id:r??newId(),values:wire(o),createdAt:isoOf(i,c),updatedAt:isoOf(a,isoOf(i,c)),visibility:`workspace`,ownedBy:null,metadata:{},objectId:objectOf(e).definition.id??e,label:``,parentId:null,ancestorIds:[],trashedWithRecordId:null,schemaVersion:1};return n.push(l),s.add(l.id),l}function find(e,n){let r=objectOf(e).records.find(e=>e.id===n);if(!r)throw new t.h(404,readNotFound(n),f);return r}function requireWritable(e,n){if(!objectOf(e).records.some(e=>e.id===n))throw new t.h(404,writeNotFound(n),f)}function update(e,n,r){let i=objectOf(e).records.find(e=>e.id===n);if(!i)throw new t.h(404,writeNotFound(n),f);return Object.assign(i.values,withoutSystemKeys(r)),i.updatedAt=now(),i}function remove(e,n){let{records:r}=objectOf(e),i=r.findIndex(e=>e.id===n);if(i===-1)throw new t.h(404,writeNotFound(n),f);r.splice(i,1)}function list(e,t,r){let{definition:i,records:a}=objectOf(e);for(let e of t.filters?.rules??[])asTheServerValidates(()=>(0,n.validateQualifiedRule)(structuredClone(e),{attributes:i.attributes}));assertServedOperators(t.filters,i);let o=Math.min(boundOf(t.limit,`limit`,20),1e3),s=boundOf(t.offset,`offset`,0);if(o===0)return{data:[],page:{hasMore:!1,total:null,countMode:`none`}};let c=r?t.q:void 0,l=a.filter(e=>matchesFilters(e,t.filters,i)).filter(e=>c===void 0||matchesSearch(e,c)).sort(compareRecords(t.sorts,i)),u=l.slice(s,s+o);return{data:u,page:{hasMore:s+u.length<l.length,total:null,countMode:`none`}}}function bulk(e,r,i){let a=i.records??i.updates??i.ids;if(!Array.isArray(a)||a.length>100)throw new t.h(400,`A bulk request carries at most 100 items.`);let o=withSystemAttributes(objectOf(e).definition);if(r===`bulk-create`){let r=[],i=[];for(let[s,c]of a.entries())if(!(0,n.isPlainRecord)(c))i.push({index:s,error:`Record data must be an object`});else try{asTheServerValidates(()=>(0,n.rejectUnknownAttributesOrThrow)(o,c)),r.push(insert(e,withoutSystemKeys(c)))}catch(e){if(!(e instanceof t.h))throw e;i.push({index:s,error:e.message})}return{created:r,errors:i}}if(r===`bulk-update`){let r=[],i=[];for(let{id:s,data:c}of a)try{if(!(0,n.isPlainRecord)(c))throw new t.h(400,`Update data must be an object`,p);requireWritable(e,s),asTheServerValidates(()=>(0,n.rejectUnknownAttributesOrThrow)(o,c)),r.push(update(e,s,c))}catch(e){if(!(e instanceof t.h))throw e;i.push({id:s,error:e.message,code:e.code??p})}return{updated:r,errors:i}}let s=[],c=[];for(let t of a)try{remove(e,t),s.push(t)}catch{c.push({id:t,error:writeNotFound(t),code:f})}return{deleted:s,errors:c}}function operation(e,r,i){let o=Array.isArray(i.steps)?i.steps:[],[s]=o;if(o.length!==1||!(0,n.isPlainRecord)(s)||s.kind!==`record.set`)throw notServed(e,r);let c=String(s.recordId),l=(0,n.isPlainRecord)(s.values)?s.values:{},u=[...a].find(([e,t])=>(t.id??e)===s.objectId)?.[0],answer=e=>({opId:i.opId,steps:[e],inverse:null});if(u===void 0||!objectOf(u).records.some(e=>e.id===c))return answer({status:`error`,recordId:c,code:f});try{asTheServerValidates(()=>(0,n.rejectUnknownAttributesOrThrow)(withSystemAttributes(objectOf(u).definition),l))}catch(e){if(!(e instanceof t.h))throw e;let n=e.code??p;return answer({status:`error`,recordId:c,code:n,...n===p&&{message:e.message}})}return answer({status:`applied`,record:update(u,c,l)})}function route(e,r,i){let[a,o,s,...c]=r.replace(/^\/+/,``).split(`/`);if(e===`POST`&&a===`operations`&&o===void 0)return operation(e,r,(0,n.isPlainRecord)(i)?i:{});if(a!==`records`||o===void 0||c.length>0)throw notServed(e,r);let l=decodeURIComponent(o),u=s===void 0?void 0:decodeURIComponent(s),d=(0,n.isPlainRecord)(i)?i:{};if(e===`POST`&&u===void 0){let e=(0,n.isPlainRecord)(d.data)?d.data:{};return asTheServerValidates(()=>(0,n.rejectUnknownAttributesOrThrow)(withSystemAttributes(objectOf(l).definition),e)),insert(l,withoutSystemKeys(e))}if(e===`POST`&&(u===`list`||u===`search`))return list(l,d,u===`search`);if(e===`POST`&&u?.startsWith(`bulk-`))return bulk(l,u,d);if(u===void 0)throw notServed(e,r);if(e===`GET`)return find(l,u);if(e===`PUT`||e===`PATCH`){if(Object.keys(d).length===0)throw new t.h(400,`Request body cannot be empty`);return requireWritable(l,u),asTheServerValidates(()=>(0,n.rejectUnknownAttributesOrThrow)(withSystemAttributes(objectOf(l).definition),d)),update(l,u,d)}if(e===`DELETE`)return remove(l,u),null;throw notServed(e,r)}function request(e,t,n){return Promise.resolve().then(()=>(takeFailure(),wire(route(e,t,n===void 0?void 0:wire(n)))))}function takeFailure(){if(c){let{status:e,failure:t}=c;throw c=null,errorFor(e,t.message??`Request failed with status ${e}`,t.code)}}let d={call:(e,t)=>Promise.resolve().then(()=>{let{path:n,body:i}=(0,r.splitOperationInput)(e,t??{});return request(e.method,n,i).then(t=>(0,r.decodeOperationOutput)(e,t??null))}),stream:(e,t)=>Promise.resolve().then(()=>{takeFailure();let{path:n}=(0,r.splitOperationInput)(e,t??{});throw notServed(e.method,n)}),get:e=>request(`GET`,e),post:(e,t)=>request(`POST`,e,t),patch:(e,t)=>request(`PATCH`,e,t),put:(e,t)=>request(`PUT`,e,t),delete:e=>request(`DELETE`,e),getText:e=>Promise.resolve().then(()=>{throw takeFailure(),notServed(`GET`,e)}),postRaw:e=>Promise.resolve().then(()=>{throw takeFailure(),notServed(`POST`,e)}),postMultipart:e=>Promise.resolve().then(()=>{throw takeFailure(),notServed(`POST`,e)})};return{transport:d,get:d.get,post:d.post,definitionOf:e=>objectOf(e).definition,seed:(e,t)=>t.map(t=>insert(e,t)),records:e=>objectOf(e).records,failNextRequestWith(e,t={}){c={status:e,failure:t}}}}function createTestStandards(t){let n=t.bundles.flatMap(e=>e.objectBuilders),i=createInMemoryApi({builders:n}),flatten=(t,n)=>e.o(i.definitionOf(t),(0,r.decodeOperationOutput)(r.recordsOperations.get,JSON.parse(JSON.stringify(n))));return{db:e.t(i.transport,n),seed:(e,t)=>i.seed(e,t).map(t=>flatten(e,t)),records:e=>i.records(e).map(t=>flatten(e,t)),failNextRequestWith:(e,t)=>i.failNextRequestWith(e,t)}}exports.UnsupportedFilterOperatorError=UnsupportedFilterOperatorError,exports.createTestStandards=createTestStandards;
package/dist/testing.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! © 2025-2026 AND YOU CREATE SAS (RCS Paris 940 190 614). Proprietary — see LICENSE (Standards SDK License 1.0). */
2
- import{a as e,o as t,t as n}from"./create-standards-B9jNTqFf.mjs";import{h as r,p as i}from"./app-Cer-0oL4.mjs";import{ValidationError as a,foldText as o,getObjectSystemAttributes as s,isPlainRecord as c,rejectUnknownAttributesOrThrow as l,validateQualifiedRule as u}from"@standards/schema";import{decodeOperationOutput as d,recordsOperations as f,splitOperationInput as p}from"@standards/schema/api";var UnsupportedFilterOperatorError=class extends Error{constructor(e,t){super(`The in-memory test workspace does not serve the "${e}" operator (on "${t}"). Test it against a real workspace.`),this.name=`UnsupportedFilterOperatorError`,this.operator=e}};const m=/* @__PURE__ */ new Set([`id`,`createdAt`,`updatedAt`]),h=/* @__PURE__ */ new Set([`createdAt`,`updatedAt`]),g=/* @__PURE__ */ new Set([`number`,`currency`]),_=/* @__PURE__ */ new Set([`select`,`status`]),v=/^\d{4}-\d{2}-\d{2}/,y=/^(\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]))(?:[T ]((?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d{1,6})?)?)(Z|[+-](?:0\d|1[0-4])(?::?[0-5]\d)?)?)?$/;function attributeValue(e,t){if(m.has(t))return e[t];let n=e.values[t];return typeof n==`object`&&n&&`value`in n&&!Array.isArray(n)?n.value:n}function isEmptyValue(e){return e==null||e===``||Array.isArray(e)&&e.length===0}function textOf(e){return e==null?null:e instanceof Date?e.toISOString():typeof e==`string`?e:JSON.stringify(e)}function members(e){return Array.isArray(e)?e.map(String):null}function dayOf(e){let t=textOf(e);if(t===null||!v.test(t))return null;let n=t.slice(0,10);return Number.isNaN(Date.parse(`${n}T00:00:00.000Z`))?null:n}const b=Date.parse(`0001-01-01T00:00:00Z`);function instantOf(e){let t=typeof e==`object`&&e&&`start`in e?e.start:e,n=typeof t==`string`?y.exec(t):null;if(!n)return null;let[,r=``,i=`00:00`,a=`Z`]=n;if(r.startsWith(`0000`))return null;let o=a===`Z`?`Z`:`${a.slice(0,3)}:${a.slice(3).replace(`:`,``)||`00`}`,s=Date.parse(`${r}T${i}${o}`);return Number.isNaN(s)||(/* @__PURE__ */ new Date(`${r}T00:00:00Z`)).toISOString().slice(0,10)!==r||s<b?null:s}function nextDay(e){let t=/* @__PURE__ */ new Date(`${e}T00:00:00.000Z`);return t.setUTCDate(t.getUTCDate()+1),t.toISOString().slice(0,10)}function isUnmodelledDate(e){if(e?.type!==`date`)return!1;let t=e;return t.endDate===!0||t.includeTime===!0}function isTimedDate(e){return e?.type===`date`&&e.includeTime===!0}function matchesDay(e,t,n,r){let i=dayOf(n);if(i===null)return!1;let a=textOf(t),o=nextDay(i),s=r?textOf(n)??i:i;switch(e){case`is`:return a!==null&&a>=s&&a<o;case`is_not`:return a===null||a<s||a>=o;case`greater_than`:return a!==null&&a>=o;case`greater_or_equal`:return a!==null&&a>=s;case`less_than`:return a!==null&&a<s;default:return a!==null&&a<o}}function compare(e,t,n){let r=textOf(e),i=textOf(t);if(r===null||i===null)return null;if(n){let e=Number(r),t=Number(i);return r===``||Number.isNaN(e)||Number.isNaN(t)?null:e-t}return r<i?-1:+(r>i)}function matchesRule(e,t,n){let r=n.attributes.find(e=>e.name===t.attribute)?.type,i=attributeValue(e,t.attribute),a=r!==void 0&&g.has(r),s=textOf(t.value),c=s===null?void 0:o(s),l=textOf(i),u=l===null?null:o(l);if((r===`date`||h.has(t.attribute))&&[`is`,`is_not`,`greater_than`,`greater_or_equal`,`less_than`,`less_or_equal`].includes(t.operator))return matchesDay(t.operator,i,t.value,h.has(t.attribute));switch(t.operator){case`is`:return r===`checkbox`||r===void 0&&typeof t.value==`boolean`?t.value===!0?i===!0:i!==!0:textOf(i)!==null&&textOf(i)===textOf(t.value);case`is_not`:return textOf(i)===null||textOf(i)!==textOf(t.value);case`contains`:return Array.isArray(i)?(Array.isArray(t.value)?t.value.map(String):[String(t.value)]).every(e=>i.map(String).includes(e)):u!==null&&c!==void 0&&u.includes(c);case`not_contains`:return i==null||!matchesRule(e,{...t,operator:`contains`},n);case`starts_with`:return u!==null&&c!==void 0&&u.startsWith(c);case`ends_with`:return u!==null&&c!==void 0&&u.endsWith(c);case`greater_than`:case`greater_or_equal`:case`less_than`:case`less_or_equal`:{let e=compare(i,t.value,a);return e===null?!1:t.operator===`greater_than`?e>0:t.operator===`greater_or_equal`?e>=0:t.operator===`less_than`?e<0:e<=0}case`is_empty`:return isEmptyValue(i);case`is_not_empty`:return!isEmptyValue(i);case`any_of`:{let e=members(t.value);return e===null||e.length===0||i==null?!1:Array.isArray(i)?i.some(t=>e.includes(String(t))):e.includes(textOf(i)??``)}case`none_of`:{let e=members(t.value);return e===null?!1:e.length===0||i==null?!0:Array.isArray(i)?!i.some(t=>e.includes(String(t))):!e.includes(textOf(i)??``)}default:throw new UnsupportedFilterOperatorError(t.operator,t.attribute)}}const x=/* @__PURE__ */ new Set([`is`,`is_not`,`contains`,`not_contains`,`starts_with`,`ends_with`,`greater_than`,`greater_or_equal`,`less_than`,`less_or_equal`,`is_empty`,`is_not_empty`,`any_of`,`none_of`]);function assertServedOperators(e,t){for(let n of e?.rules??[])if(!x.has(n.operator)||n.attribute.startsWith(`metadata.`)||isUnmodelledDate(t.attributes.find(e=>e.name===n.attribute))&&n.operator!==`is_empty`&&n.operator!==`is_not_empty`)throw new UnsupportedFilterOperatorError(n.operator,n.attribute)}function matchesFilters(e,t,n){let r=t?.rules??[];if(r.length===0)return!0;let i=r.map(t=>matchesRule(e,t,n));return t?.combinator===`or`?i.some(Boolean):i.every(Boolean)}function matchesSearch(e,t){let n=t.trim().toLowerCase();return n===``||Object.values(e.values).some(e=>(Array.isArray(e)?e:[e]).some(e=>typeof e==`string`&&e.toLowerCase().includes(n)))}function sortKey(e,t,n){let r=attributeValue(e,t),i=n.attributes.find(e=>e.name===t);if(i&&_.has(i.type)){let e=(i.options??[]).findIndex(e=>e.value===r);return{position:e===-1?null:e,value:r}}return r}function isOptionKey(e){return typeof e==`object`&&!!e&&`position`in e}function compareOptionKeys(e,t,n){let r=n===`desc`?-1:1;return e.position!==null&&t.position!==null?r*(e.position-t.position):e.position!==null||t.position!==null?e.position===null?1:-1:r*(compare(e.value,t.value,!1)??0)}function compareInstants(e,t,n){let r=instantOf(e.values[n.attribute]),i=instantOf(t.values[n.attribute]);return r===i?0:r===null||i===null?r===null?1:-1:n.direction===`desc`?i-r:r-i}function compareRecords(e,t){let n=e&&e.length>0?[...e]:[{attribute:`createdAt`,direction:`desc`}];return n.some(e=>e.attribute===`id`)||n.push({attribute:`id`,direction:`asc`}),(e,r)=>{for(let i of n){let n=t.attributes.find(e=>e.name===i.attribute),a=n?.type;if(isTimedDate(n)){let t=compareInstants(e,r,i);if(t!==0)return t;continue}let o=sortKey(e,i.attribute,t),s=sortKey(r,i.attribute,t),c=isOptionKey(o)?o.value:o,l=isOptionKey(s)?s.value:s,u=textOf(c)===null,d=textOf(l)===null;if(u||d){if(u&&d)continue;return u?1:-1}if(isOptionKey(o)&&isOptionKey(s)){let e=compareOptionKeys(o,s,i.direction);if(e!==0)return e;continue}let f=compare(o,s,a!==void 0&&g.has(a))??0;if(f!==0)return i.direction===`desc`?-f:f}return 0}}const S=`SCHEMA_RECORD_NOT_FOUND`,C=`SCHEMA_VALIDATION_FAILED`,readNotFound=e=>`Record "${e}" not found.`,writeNotFound=e=>`Record with id "${e}" not found`,w=[`id`,`createdAt`,`updatedAt`];function withSystemAttributes(e){return{...e,attributes:[...e.attributes,...s(e)]}}function withoutSystemKeys(e){let t={...e};for(let e of w)delete t[e];return t}function boundOf(e,t,n){if(e==null)return n;if(typeof e!=`number`||!Number.isSafeInteger(e)||e<0)throw new r(400,`${t} must be a non-negative integer`);return e}function errorFor(e,t,n){return e===401||e===403?new i(e,t,n):new r(e,t,n)}function asTheServerValidates(e){try{e()}catch(e){throw e instanceof a?new r(400,e.message,e.code):e}}function notServed(e,t){return new r(501,`The in-memory test workspace does not serve ${e} ${t}: only the records API is in memory.`)}function isoOf(e,t){return e===void 0?t:e instanceof Date?e.toISOString():new Date(e).toISOString()}function wire(e){return JSON.parse(JSON.stringify(e))}function createInMemoryApi(t){let n=/* @__PURE__ */ new Map;for(let r of t.builders){let t=e(r);n.set(t.name,t)}let i=new Map([...n.keys()].map(e=>[e,[]])),a=/* @__PURE__ */ new Set,o=null,s=0,f=1;function now(){return s=Math.max(Date.now(),s+1),new Date(s).toISOString()}function newId(){let e;do e=`00000000-0000-4000-8000-${(f++).toString(16).padStart(12,`0`)}`;while(a.has(e));return e}function objectOf(e){let t=n.get(e),a=i.get(e);if(!(t&&a))throw new r(404,`Object "${e}" not found. Make sure the object exists and you have access to it.`);return{definition:t,records:a}}function insert(e,t){let{records:n}=objectOf(e),{id:r,createdAt:i,updatedAt:o,...s}=t,c=now(),l={id:r??newId(),values:wire(s),createdAt:isoOf(i,c),updatedAt:isoOf(o,isoOf(i,c)),visibility:`workspace`,ownedBy:null,metadata:{},objectId:objectOf(e).definition.id??e,label:``,parentId:null,ancestorIds:[],trashedWithRecordId:null,schemaVersion:1};return n.push(l),a.add(l.id),l}function find(e,t){let n=objectOf(e).records.find(e=>e.id===t);if(!n)throw new r(404,readNotFound(t),S);return n}function requireWritable(e,t){if(!objectOf(e).records.some(e=>e.id===t))throw new r(404,writeNotFound(t),S)}function update(e,t,n){let i=objectOf(e).records.find(e=>e.id===t);if(!i)throw new r(404,writeNotFound(t),S);return Object.assign(i.values,withoutSystemKeys(n)),i.updatedAt=now(),i}function remove(e,t){let{records:n}=objectOf(e),i=n.findIndex(e=>e.id===t);if(i===-1)throw new r(404,writeNotFound(t),S);n.splice(i,1)}function list(e,t,n){let{definition:r,records:i}=objectOf(e);for(let e of t.filters?.rules??[])asTheServerValidates(()=>u(structuredClone(e),{attributes:r.attributes}));assertServedOperators(t.filters,r);let a=Math.min(boundOf(t.limit,`limit`,20),1e3),o=boundOf(t.offset,`offset`,0);if(a===0)return{data:[],page:{hasMore:!1,total:null,countMode:`none`}};let s=n?t.q:void 0,c=i.filter(e=>matchesFilters(e,t.filters,r)).filter(e=>s===void 0||matchesSearch(e,s)).sort(compareRecords(t.sorts,r)),l=c.slice(o,o+a);return{data:l,page:{hasMore:o+l.length<c.length,total:null,countMode:`none`}}}function bulk(e,t,n){let i=n.records??n.updates??n.ids;if(!Array.isArray(i)||i.length>100)throw new r(400,`A bulk request carries at most 100 items.`);let a=withSystemAttributes(objectOf(e).definition);if(t===`bulk-create`){let t=[],n=[];for(let[o,s]of i.entries())if(!c(s))n.push({index:o,error:`Record data must be an object`});else try{asTheServerValidates(()=>l(a,s)),t.push(insert(e,withoutSystemKeys(s)))}catch(e){if(!(e instanceof r))throw e;n.push({index:o,error:e.message})}return{created:t,errors:n}}if(t===`bulk-update`){let t=[],n=[];for(let{id:o,data:s}of i)try{if(!c(s))throw new r(400,`Update data must be an object`,C);requireWritable(e,o),asTheServerValidates(()=>l(a,s)),t.push(update(e,o,s))}catch(e){if(!(e instanceof r))throw e;n.push({id:o,error:e.message,code:e.code??C})}return{updated:t,errors:n}}let o=[],s=[];for(let t of i)try{remove(e,t),o.push(t)}catch{s.push({id:t,error:writeNotFound(t),code:S})}return{deleted:o,errors:s}}function operation(e,t,i){let a=Array.isArray(i.steps)?i.steps:[],[o]=a;if(a.length!==1||!c(o)||o.kind!==`record.set`)throw notServed(e,t);let s=String(o.recordId),u=c(o.values)?o.values:{},d=[...n].find(([e,t])=>(t.id??e)===o.objectId)?.[0],answer=e=>({opId:i.opId,steps:[e],inverse:null});if(d===void 0||!objectOf(d).records.some(e=>e.id===s))return answer({status:`error`,recordId:s,code:S});try{asTheServerValidates(()=>l(withSystemAttributes(objectOf(d).definition),u))}catch(e){if(!(e instanceof r))throw e;let t=e.code??C;return answer({status:`error`,recordId:s,code:t,...t===C&&{message:e.message}})}return answer({status:`applied`,record:update(d,s,u)})}function route(e,t,n){let[i,a,o,...s]=t.replace(/^\/+/,``).split(`/`);if(e===`POST`&&i===`operations`&&a===void 0)return operation(e,t,c(n)?n:{});if(i!==`records`||a===void 0||s.length>0)throw notServed(e,t);let u=decodeURIComponent(a),d=o===void 0?void 0:decodeURIComponent(o),f=c(n)?n:{};if(e===`POST`&&d===void 0){let e=c(f.data)?f.data:{};return asTheServerValidates(()=>l(withSystemAttributes(objectOf(u).definition),e)),insert(u,withoutSystemKeys(e))}if(e===`POST`&&(d===`list`||d===`search`))return list(u,f,d===`search`);if(e===`POST`&&d?.startsWith(`bulk-`))return bulk(u,d,f);if(d===void 0)throw notServed(e,t);if(e===`GET`)return find(u,d);if(e===`PUT`||e===`PATCH`){if(Object.keys(f).length===0)throw new r(400,`Request body cannot be empty`);return requireWritable(u,d),asTheServerValidates(()=>l(withSystemAttributes(objectOf(u).definition),f)),update(u,d,f)}if(e===`DELETE`)return remove(u,d),null;throw notServed(e,t)}function request(e,t,n){return Promise.resolve().then(()=>(takeFailure(),wire(route(e,t,n===void 0?void 0:wire(n)))))}function takeFailure(){if(o){let{status:e,failure:t}=o;throw o=null,errorFor(e,t.message??`Request failed with status ${e}`,t.code)}}let m={call:(e,t)=>Promise.resolve().then(()=>{let{path:n,body:r}=p(e,t??{});return request(e.method,n,r).then(t=>d(e,t??null))}),stream:(e,t)=>Promise.resolve().then(()=>{takeFailure();let{path:n}=p(e,t??{});throw notServed(e.method,n)}),get:e=>request(`GET`,e),post:(e,t)=>request(`POST`,e,t),patch:(e,t)=>request(`PATCH`,e,t),put:(e,t)=>request(`PUT`,e,t),delete:e=>request(`DELETE`,e),getText:e=>Promise.resolve().then(()=>{throw takeFailure(),notServed(`GET`,e)}),postRaw:e=>Promise.resolve().then(()=>{throw takeFailure(),notServed(`POST`,e)}),postMultipart:e=>Promise.resolve().then(()=>{throw takeFailure(),notServed(`POST`,e)})};return{transport:m,get:m.get,post:m.post,definitionOf:e=>objectOf(e).definition,seed:(e,t)=>t.map(t=>insert(e,t)),records:e=>objectOf(e).records,failNextRequestWith(e,t={}){o={status:e,failure:t}}}}function createTestStandards(e){let r=e.bundles.flatMap(e=>e.objectBuilders),i=createInMemoryApi({builders:r}),flatten=(e,n)=>t(i.definitionOf(e),d(f.get,JSON.parse(JSON.stringify(n))));return{db:n(i.transport,r),seed:(e,t)=>i.seed(e,t).map(t=>flatten(e,t)),records:e=>i.records(e).map(t=>flatten(e,t)),failNextRequestWith:(e,t)=>i.failNextRequestWith(e,t)}}export{UnsupportedFilterOperatorError,createTestStandards};
2
+ import{a as e,o as t,t as n}from"./create-standards-Dq4tC8T6.mjs";import{h as r,p as i}from"./app-Cer-0oL4.mjs";import{ValidationError as a,foldText as o,getObjectSystemAttributes as s,isPlainRecord as c,rejectUnknownAttributesOrThrow as l,validateQualifiedRule as u}from"@standards/schema";import{decodeOperationOutput as d,recordsOperations as f,splitOperationInput as p}from"@standards/schema/api";var UnsupportedFilterOperatorError=class extends Error{constructor(e,t){super(`The in-memory test workspace does not serve the "${e}" operator (on "${t}"). Test it against a real workspace.`),this.name=`UnsupportedFilterOperatorError`,this.operator=e}};const m=/* @__PURE__ */ new Set([`id`,`createdAt`,`updatedAt`]),h=/* @__PURE__ */ new Set([`createdAt`,`updatedAt`]),g=/* @__PURE__ */ new Set([`number`,`currency`]),_=/* @__PURE__ */ new Set([`select`,`status`]),v=/^\d{4}-\d{2}-\d{2}/,y=/^(\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]))(?:[T ]((?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d{1,6})?)?)(Z|[+-](?:0\d|1[0-4])(?::?[0-5]\d)?)?)?$/;function attributeValue(e,t){if(m.has(t))return e[t];let n=e.values[t];return typeof n==`object`&&n&&`value`in n&&!Array.isArray(n)?n.value:n}function isEmptyValue(e){return e==null||e===``||Array.isArray(e)&&e.length===0}function textOf(e){return e==null?null:e instanceof Date?e.toISOString():typeof e==`string`?e:JSON.stringify(e)}function members(e){return Array.isArray(e)?e.map(String):null}function dayOf(e){let t=textOf(e);if(t===null||!v.test(t))return null;let n=t.slice(0,10);return Number.isNaN(Date.parse(`${n}T00:00:00.000Z`))?null:n}const b=Date.parse(`0001-01-01T00:00:00Z`);function instantOf(e){let t=typeof e==`object`&&e&&`start`in e?e.start:e,n=typeof t==`string`?y.exec(t):null;if(!n)return null;let[,r=``,i=`00:00`,a=`Z`]=n;if(r.startsWith(`0000`))return null;let o=a===`Z`?`Z`:`${a.slice(0,3)}:${a.slice(3).replace(`:`,``)||`00`}`,s=Date.parse(`${r}T${i}${o}`);return Number.isNaN(s)||(/* @__PURE__ */ new Date(`${r}T00:00:00Z`)).toISOString().slice(0,10)!==r||s<b?null:s}function nextDay(e){let t=/* @__PURE__ */ new Date(`${e}T00:00:00.000Z`);return t.setUTCDate(t.getUTCDate()+1),t.toISOString().slice(0,10)}function isUnmodelledDate(e){if(e?.type!==`date`)return!1;let t=e;return t.endDate===!0||t.includeTime===!0}function isTimedDate(e){return e?.type===`date`&&e.includeTime===!0}function matchesDay(e,t,n,r){let i=dayOf(n);if(i===null)return!1;let a=textOf(t),o=nextDay(i),s=r?textOf(n)??i:i;switch(e){case`is`:return a!==null&&a>=s&&a<o;case`is_not`:return a===null||a<s||a>=o;case`greater_than`:return a!==null&&a>=o;case`greater_or_equal`:return a!==null&&a>=s;case`less_than`:return a!==null&&a<s;default:return a!==null&&a<o}}function compare(e,t,n){let r=textOf(e),i=textOf(t);if(r===null||i===null)return null;if(n){let e=Number(r),t=Number(i);return r===``||Number.isNaN(e)||Number.isNaN(t)?null:e-t}return r<i?-1:+(r>i)}function matchesRule(e,t,n){let r=n.attributes.find(e=>e.name===t.attribute)?.type,i=attributeValue(e,t.attribute),a=r!==void 0&&g.has(r),s=textOf(t.value),c=s===null?void 0:o(s),l=textOf(i),u=l===null?null:o(l);if((r===`date`||h.has(t.attribute))&&[`is`,`is_not`,`greater_than`,`greater_or_equal`,`less_than`,`less_or_equal`].includes(t.operator))return matchesDay(t.operator,i,t.value,h.has(t.attribute));switch(t.operator){case`is`:return r===`checkbox`||r===void 0&&typeof t.value==`boolean`?t.value===!0?i===!0:i!==!0:textOf(i)!==null&&textOf(i)===textOf(t.value);case`is_not`:return textOf(i)===null||textOf(i)!==textOf(t.value);case`contains`:return Array.isArray(i)?(Array.isArray(t.value)?t.value.map(String):[String(t.value)]).every(e=>i.map(String).includes(e)):u!==null&&c!==void 0&&u.includes(c);case`not_contains`:return i==null||!matchesRule(e,{...t,operator:`contains`},n);case`starts_with`:return u!==null&&c!==void 0&&u.startsWith(c);case`ends_with`:return u!==null&&c!==void 0&&u.endsWith(c);case`greater_than`:case`greater_or_equal`:case`less_than`:case`less_or_equal`:{let e=compare(i,t.value,a);return e===null?!1:t.operator===`greater_than`?e>0:t.operator===`greater_or_equal`?e>=0:t.operator===`less_than`?e<0:e<=0}case`is_empty`:return isEmptyValue(i);case`is_not_empty`:return!isEmptyValue(i);case`any_of`:{let e=members(t.value);return e===null||e.length===0||i==null?!1:Array.isArray(i)?i.some(t=>e.includes(String(t))):e.includes(textOf(i)??``)}case`none_of`:{let e=members(t.value);return e===null?!1:e.length===0||i==null?!0:Array.isArray(i)?!i.some(t=>e.includes(String(t))):!e.includes(textOf(i)??``)}default:throw new UnsupportedFilterOperatorError(t.operator,t.attribute)}}const x=/* @__PURE__ */ new Set([`is`,`is_not`,`contains`,`not_contains`,`starts_with`,`ends_with`,`greater_than`,`greater_or_equal`,`less_than`,`less_or_equal`,`is_empty`,`is_not_empty`,`any_of`,`none_of`]);function assertServedOperators(e,t){for(let n of e?.rules??[])if(!x.has(n.operator)||n.attribute.startsWith(`metadata.`)||isUnmodelledDate(t.attributes.find(e=>e.name===n.attribute))&&n.operator!==`is_empty`&&n.operator!==`is_not_empty`)throw new UnsupportedFilterOperatorError(n.operator,n.attribute)}function matchesFilters(e,t,n){let r=t?.rules??[];if(r.length===0)return!0;let i=r.map(t=>matchesRule(e,t,n));return t?.combinator===`or`?i.some(Boolean):i.every(Boolean)}function matchesSearch(e,t){let n=t.trim().toLowerCase();return n===``||Object.values(e.values).some(e=>(Array.isArray(e)?e:[e]).some(e=>typeof e==`string`&&e.toLowerCase().includes(n)))}function sortKey(e,t,n){let r=attributeValue(e,t),i=n.attributes.find(e=>e.name===t);if(i&&_.has(i.type)){let e=(i.options??[]).findIndex(e=>e.value===r);return{position:e===-1?null:e,value:r}}return r}function isOptionKey(e){return typeof e==`object`&&!!e&&`position`in e}function compareOptionKeys(e,t,n){let r=n===`desc`?-1:1;return e.position!==null&&t.position!==null?r*(e.position-t.position):e.position!==null||t.position!==null?e.position===null?1:-1:r*(compare(e.value,t.value,!1)??0)}function compareInstants(e,t,n){let r=instantOf(e.values[n.attribute]),i=instantOf(t.values[n.attribute]);return r===i?0:r===null||i===null?r===null?1:-1:n.direction===`desc`?i-r:r-i}function compareRecords(e,t){let n=e&&e.length>0?[...e]:[{attribute:`createdAt`,direction:`desc`}];return n.some(e=>e.attribute===`id`)||n.push({attribute:`id`,direction:`asc`}),(e,r)=>{for(let i of n){let n=t.attributes.find(e=>e.name===i.attribute),a=n?.type;if(isTimedDate(n)){let t=compareInstants(e,r,i);if(t!==0)return t;continue}let o=sortKey(e,i.attribute,t),s=sortKey(r,i.attribute,t),c=isOptionKey(o)?o.value:o,l=isOptionKey(s)?s.value:s,u=textOf(c)===null,d=textOf(l)===null;if(u||d){if(u&&d)continue;return u?1:-1}if(isOptionKey(o)&&isOptionKey(s)){let e=compareOptionKeys(o,s,i.direction);if(e!==0)return e;continue}let f=compare(o,s,a!==void 0&&g.has(a))??0;if(f!==0)return i.direction===`desc`?-f:f}return 0}}const S=`SCHEMA_RECORD_NOT_FOUND`,C=`SCHEMA_VALIDATION_FAILED`,readNotFound=e=>`Record "${e}" not found.`,writeNotFound=e=>`Record with id "${e}" not found`,w=[`id`,`createdAt`,`updatedAt`];function withSystemAttributes(e){return{...e,attributes:[...e.attributes,...s(e)]}}function withoutSystemKeys(e){let t={...e};for(let e of w)delete t[e];return t}function boundOf(e,t,n){if(e==null)return n;if(typeof e!=`number`||!Number.isSafeInteger(e)||e<0)throw new r(400,`${t} must be a non-negative integer`);return e}function errorFor(e,t,n){return e===401||e===403?new i(e,t,n):new r(e,t,n)}function asTheServerValidates(e){try{e()}catch(e){throw e instanceof a?new r(400,e.message,e.code):e}}function notServed(e,t){return new r(501,`The in-memory test workspace does not serve ${e} ${t}: only the records API is in memory.`)}function isoOf(e,t){return e===void 0?t:e instanceof Date?e.toISOString():new Date(e).toISOString()}function wire(e){return JSON.parse(JSON.stringify(e))}function createInMemoryApi(t){let n=/* @__PURE__ */ new Map;for(let r of t.builders){let t=e(r);n.set(t.name,t)}let i=new Map([...n.keys()].map(e=>[e,[]])),a=/* @__PURE__ */ new Set,o=null,s=0,f=1;function now(){return s=Math.max(Date.now(),s+1),new Date(s).toISOString()}function newId(){let e;do e=`00000000-0000-4000-8000-${(f++).toString(16).padStart(12,`0`)}`;while(a.has(e));return e}function objectOf(e){let t=n.get(e),a=i.get(e);if(!(t&&a))throw new r(404,`Object "${e}" not found. Make sure the object exists and you have access to it.`);return{definition:t,records:a}}function insert(e,t){let{records:n}=objectOf(e),{id:r,createdAt:i,updatedAt:o,...s}=t,c=now(),l={id:r??newId(),values:wire(s),createdAt:isoOf(i,c),updatedAt:isoOf(o,isoOf(i,c)),visibility:`workspace`,ownedBy:null,metadata:{},objectId:objectOf(e).definition.id??e,label:``,parentId:null,ancestorIds:[],trashedWithRecordId:null,schemaVersion:1};return n.push(l),a.add(l.id),l}function find(e,t){let n=objectOf(e).records.find(e=>e.id===t);if(!n)throw new r(404,readNotFound(t),S);return n}function requireWritable(e,t){if(!objectOf(e).records.some(e=>e.id===t))throw new r(404,writeNotFound(t),S)}function update(e,t,n){let i=objectOf(e).records.find(e=>e.id===t);if(!i)throw new r(404,writeNotFound(t),S);return Object.assign(i.values,withoutSystemKeys(n)),i.updatedAt=now(),i}function remove(e,t){let{records:n}=objectOf(e),i=n.findIndex(e=>e.id===t);if(i===-1)throw new r(404,writeNotFound(t),S);n.splice(i,1)}function list(e,t,n){let{definition:r,records:i}=objectOf(e);for(let e of t.filters?.rules??[])asTheServerValidates(()=>u(structuredClone(e),{attributes:r.attributes}));assertServedOperators(t.filters,r);let a=Math.min(boundOf(t.limit,`limit`,20),1e3),o=boundOf(t.offset,`offset`,0);if(a===0)return{data:[],page:{hasMore:!1,total:null,countMode:`none`}};let s=n?t.q:void 0,c=i.filter(e=>matchesFilters(e,t.filters,r)).filter(e=>s===void 0||matchesSearch(e,s)).sort(compareRecords(t.sorts,r)),l=c.slice(o,o+a);return{data:l,page:{hasMore:o+l.length<c.length,total:null,countMode:`none`}}}function bulk(e,t,n){let i=n.records??n.updates??n.ids;if(!Array.isArray(i)||i.length>100)throw new r(400,`A bulk request carries at most 100 items.`);let a=withSystemAttributes(objectOf(e).definition);if(t===`bulk-create`){let t=[],n=[];for(let[o,s]of i.entries())if(!c(s))n.push({index:o,error:`Record data must be an object`});else try{asTheServerValidates(()=>l(a,s)),t.push(insert(e,withoutSystemKeys(s)))}catch(e){if(!(e instanceof r))throw e;n.push({index:o,error:e.message})}return{created:t,errors:n}}if(t===`bulk-update`){let t=[],n=[];for(let{id:o,data:s}of i)try{if(!c(s))throw new r(400,`Update data must be an object`,C);requireWritable(e,o),asTheServerValidates(()=>l(a,s)),t.push(update(e,o,s))}catch(e){if(!(e instanceof r))throw e;n.push({id:o,error:e.message,code:e.code??C})}return{updated:t,errors:n}}let o=[],s=[];for(let t of i)try{remove(e,t),o.push(t)}catch{s.push({id:t,error:writeNotFound(t),code:S})}return{deleted:o,errors:s}}function operation(e,t,i){let a=Array.isArray(i.steps)?i.steps:[],[o]=a;if(a.length!==1||!c(o)||o.kind!==`record.set`)throw notServed(e,t);let s=String(o.recordId),u=c(o.values)?o.values:{},d=[...n].find(([e,t])=>(t.id??e)===o.objectId)?.[0],answer=e=>({opId:i.opId,steps:[e],inverse:null});if(d===void 0||!objectOf(d).records.some(e=>e.id===s))return answer({status:`error`,recordId:s,code:S});try{asTheServerValidates(()=>l(withSystemAttributes(objectOf(d).definition),u))}catch(e){if(!(e instanceof r))throw e;let t=e.code??C;return answer({status:`error`,recordId:s,code:t,...t===C&&{message:e.message}})}return answer({status:`applied`,record:update(d,s,u)})}function route(e,t,n){let[i,a,o,...s]=t.replace(/^\/+/,``).split(`/`);if(e===`POST`&&i===`operations`&&a===void 0)return operation(e,t,c(n)?n:{});if(i!==`records`||a===void 0||s.length>0)throw notServed(e,t);let u=decodeURIComponent(a),d=o===void 0?void 0:decodeURIComponent(o),f=c(n)?n:{};if(e===`POST`&&d===void 0){let e=c(f.data)?f.data:{};return asTheServerValidates(()=>l(withSystemAttributes(objectOf(u).definition),e)),insert(u,withoutSystemKeys(e))}if(e===`POST`&&(d===`list`||d===`search`))return list(u,f,d===`search`);if(e===`POST`&&d?.startsWith(`bulk-`))return bulk(u,d,f);if(d===void 0)throw notServed(e,t);if(e===`GET`)return find(u,d);if(e===`PUT`||e===`PATCH`){if(Object.keys(f).length===0)throw new r(400,`Request body cannot be empty`);return requireWritable(u,d),asTheServerValidates(()=>l(withSystemAttributes(objectOf(u).definition),f)),update(u,d,f)}if(e===`DELETE`)return remove(u,d),null;throw notServed(e,t)}function request(e,t,n){return Promise.resolve().then(()=>(takeFailure(),wire(route(e,t,n===void 0?void 0:wire(n)))))}function takeFailure(){if(o){let{status:e,failure:t}=o;throw o=null,errorFor(e,t.message??`Request failed with status ${e}`,t.code)}}let m={call:(e,t)=>Promise.resolve().then(()=>{let{path:n,body:r}=p(e,t??{});return request(e.method,n,r).then(t=>d(e,t??null))}),stream:(e,t)=>Promise.resolve().then(()=>{takeFailure();let{path:n}=p(e,t??{});throw notServed(e.method,n)}),get:e=>request(`GET`,e),post:(e,t)=>request(`POST`,e,t),patch:(e,t)=>request(`PATCH`,e,t),put:(e,t)=>request(`PUT`,e,t),delete:e=>request(`DELETE`,e),getText:e=>Promise.resolve().then(()=>{throw takeFailure(),notServed(`GET`,e)}),postRaw:e=>Promise.resolve().then(()=>{throw takeFailure(),notServed(`POST`,e)}),postMultipart:e=>Promise.resolve().then(()=>{throw takeFailure(),notServed(`POST`,e)})};return{transport:m,get:m.get,post:m.post,definitionOf:e=>objectOf(e).definition,seed:(e,t)=>t.map(t=>insert(e,t)),records:e=>objectOf(e).records,failNextRequestWith(e,t={}){o={status:e,failure:t}}}}function createTestStandards(e){let r=e.bundles.flatMap(e=>e.objectBuilders),i=createInMemoryApi({builders:r}),flatten=(e,n)=>t(i.definitionOf(e),d(f.get,JSON.parse(JSON.stringify(n))));return{db:n(i.transport,r),seed:(e,t)=>i.seed(e,t).map(t=>flatten(e,t)),records:e=>i.records(e).map(t=>flatten(e,t)),failNextRequestWith:(e,t)=>i.failNextRequestWith(e,t)}}export{UnsupportedFilterOperatorError,createTestStandards};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@standards/client",
3
- "version": "1.0.0-alpha.442",
3
+ "version": "1.0.0-alpha.443",
4
4
  "description": "Public TypeScript client for Standards: declare schema sources with the fluent builders, sync them to a hosted tenant, and operate typed records over the REST API.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -47,7 +47,7 @@
47
47
  "node": ">=22"
48
48
  },
49
49
  "dependencies": {
50
- "@standards/schema": "1.0.0-alpha.442"
50
+ "@standards/schema": "1.0.0-alpha.443"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "^25.6.0",
@@ -1,4 +0,0 @@
1
- /*! © 2025-2026 AND YOU CREATE SAS (RCS Paris 940 190 614). Proprietary — see LICENSE (Standards SDK License 1.0). */
2
- import{d as e,f as t,h as n,i as r,m as i,o as a,t as o}from"./app-Cer-0oL4.mjs";import{AggregateValidationError as s,DuplicateError as c,RecordQuery as l,SCHEMA_ERROR_HTTP_STATUS as u,SchemaErrorCode as d,decodeRecordValues as f,encodeRecordValues as p,isPlainRecord as m}from"@standards/schema";import{buildOperationPath as h,bundlesOperations as g,callerOf as _,decodeOperationOutput as v,recordAccessOperations as y,recordOperationsOperations as b,recordsOperations as x}from"@standards/schema/api";async function readInstalled(e,t){try{return await e.call(g.get,{name:t})}catch(e){if(e instanceof n&&e.status===404)return null;throw e}}async function syncBundle(r,i,a={}){let o=await i.build(),s=await readInstalled(r,o.name);if(s?.hash===o.hash&&s.label===o.label&&s.description===o.description&&s.uses.join(`
3
- `)===o.uses.join(`
4
- `))return{applied:!1,hash:o.hash};let c=a.resolutions&&a.resolutions.length>0?{...o,resolutions:a.resolutions}:o;try{return await r.call(g.sync,{name:o.name,bundle:c})}catch(r){throw r instanceof n&&r.status===409?new e(r.status,r.message,r.code):r instanceof n&&r.status===400?new t(r.status,r.message,r.code):r}}function objectKeyOf(e){return e.replace(/-([a-z0-9])/g,(e,t)=>t.toUpperCase())}const S=/* @__PURE__ */ new Set([`from`,`bundles`,`contract`,`as`]);function assertObjectKeys(e){let t=/* @__PURE__ */ new Map;for(let n of e){if(n.includes(`--`)||n.endsWith(`-`))throw new i(`Object "${n}" has a doubled or trailing hyphen, which has no client key. Rename the object.`);let e=objectKeyOf(n);if(S.has(e))throw new i(`Object "${n}" maps to the client key "${e}", which is reserved. Rename the object.`);let r=t.get(e);if(r!==void 0&&r!==n)throw new i(`Objects "${r}" and "${n}" both map to the client key "${e}". Rename one of them.`);t.set(e,n)}}function assertObjectNames(e){let t=/* @__PURE__ */ new Set;for(let n of e){if(t.has(n))throw new c(`object`,n);t.add(n)}assertObjectKeys(e)}function readRecord(e,t){let{values:n,...r}=t;return m(n)?{...r,...f(e,n)}:t}var C=class RecordsQueryImpl extends l{constructor(e,t,n,r={object:t,combinator:`and`,rules:[],sorts:[]}){super(r),this.transport=e,this.objectName=t,this.definition=n}with(e){return new RecordsQueryImpl(this.transport,this.objectName,this.definition,{...this.state,...e})}body(){let e={};return this.state.search!==void 0&&(e.q=this.state.search),this.state.rules.length>0&&(e.filters={combinator:this.state.combinator,rules:this.state.rules}),this.state.sorts.length>0&&(e.sorts=this.state.sorts),this.state.limit!==void 0&&(e.limit=this.state.limit),this.state.offset!==void 0&&(e.offset=this.state.offset),e}revive(e){return readRecord(this.definition,e)}async export(e,t={}){if(!this.transport.postRaw)throw new i(`export() needs a transport with postRaw(path, body): Promise<Response>`);let{filters:n,sorts:r}=this.body(),{ids:a,locale:o,filename:s}=t;return await this.transport.postRaw(h(x.export,{objectName:this.objectName}),{q:this.state.search??``,...n?{filters:n}:{},...r?{sorts:r}:{},columns:e,...a?{ids:a}:{},...o?{locale:o}:{},timezone:t.timezone??Intl.DateTimeFormat().resolvedOptions().timeZone,...s?{filename:s}:{}})}async aggregate(e){if(this.state.search!==void 0)throw new s(d.AGGREGATE_SEARCH_UNSUPPORTED,`An aggregate cannot be narrowed by a search; use filters instead`);let t={...e,query:this.toDefinition(),timezone:e.timezone??Intl.DateTimeFormat().resolvedOptions().timeZone};return await this.transport.call(x.aggregate,{objectName:this.objectName,...t})}async fetchPage(){let e={objectName:this.objectName,...this.body()},t=this.state.search===void 0?await this.transport.call(x.list,e):await this.transport.call(x.search,e);return{records:t.data.map(e=>this.revive(e)),page:t.page}}async fetch(){let{records:e,page:t}=await this.fetchPage();return{records:e,total:t.total}}async all(){if(this.state.limit!==void 0&&this.state.limit<0)return(await this.fetch()).records;let e=this.state.limit??1/0,t=[],n=this.state.offset??0;for(;;){let r=Math.min(1e3,e-t.length);if(r<=0)return t;let{records:i,page:a}=await this.with({limit:r,offset:n}).fetchPage();if(t.push(...i),!a.hasMore)return t;let o=a.nextOffset??n+i.length;if(o<=n)return t;n=o}}async single(){let{records:e}=await this.limit(1).fetch();return e[0]??null}async get(e){let t=await this.transport.call(x.get,{objectName:this.objectName,id:e});return this.revive(t)}async create(e,{allowDraft:t,metadata:n}={}){let r={...t!==void 0&&{allowDraft:t},...n!==void 0&&{metadata:n}},i=await this.transport.call(x.create,{objectName:this.objectName,data:p(this.definition,e),...Object.keys(r).length>0&&{options:r}});return this.revive(i)}async update(e,t,{metadata:n}={}){let r=p(this.definition,t);if(n===void 0){let t=await this.transport.call(x.update,{objectName:this.objectName,id:e,values:r});return this.revive(t)}let{objectId:i}=await this.transport.call(x.get,{objectName:this.objectName,id:e}),{steps:o}=await this.transport.call(b.execute,{opId:crypto.randomUUID(),steps:[{kind:`record.set`,objectId:i,recordId:e,values:r,metadata:n}]}),[s]=o;if(s===void 0||s.status===`error`){let e=s?.code,t=e===void 0?500:u[e];throw a(t,JSON.stringify({message:s?.message,code:e}))}let c=v(x.get,s.record);return this.revive(c)}async delete(e){await this.transport.call(x.delete,{objectName:this.objectName,id:e})}async inChunks(e,t){for(let n=0;n<e.length;n+=100)await t(e.slice(n,n+100),n)}async createMany(e){let t={created:[],errors:[]};return await this.inChunks(e,async(e,n)=>{let r=await this.transport.call(x.bulkCreate,{objectName:this.objectName,records:e.map(e=>p(this.definition,e))});t.created.push(...r.created.map(e=>this.revive(e))),t.errors.push(...r.errors.map(e=>({...e,index:e.index+n})))}),t}async updateMany(e){let t={updated:[],errors:[]};return await this.inChunks(e,async e=>{let n=await this.transport.call(x.bulkUpdate,{objectName:this.objectName,updates:e.map(({id:e,data:t})=>({id:e,data:p(this.definition,t)}))});t.updated.push(...n.updated.map(e=>this.revive(e))),t.errors.push(...n.errors)}),t}async deleteMany(e){let t={deleted:[],errors:[]};return await this.inChunks(e,async e=>{let n=await this.transport.call(x.bulkDelete,{objectName:this.objectName,ids:e});t.deleted.push(...n.deleted),t.errors.push(...n.errors)}),t}async listAccess(e){return await this.transport.call(y.list,{objectName:this.objectName,recordId:e})}async grantAccess(e,t,n){return await this.transport.call(y.grant,{objectName:this.objectName,recordId:e,actorId:t,role:n})}async revokeAccess(e,t){return await this.transport.call(y.revoke,{objectName:this.objectName,recordId:e,actorId:t})}async clearAccess(e){return await this.transport.call(y.clear,{objectName:this.objectName,recordId:e})}};const w=/* @__PURE__ */ new WeakMap;function definitionOf(e){let t=w.get(e);if(t)return t;let n=e.build();return w.set(e,n),n}function createRecordsQuery(e,t){if(typeof t==`string`)return new C(e,t,null);let n=definitionOf(t);return new C(e,n.name,n)}function readEnvironment(){return typeof process>`u`||!process.env?{}:{baseUrl:process.env.STANDARDS_API_URL||void 0,apiKey:process.env.STANDARDS_API_KEY||void 0}}function resolveConfig(e){if(globalThis.window!==void 0){if(e.apiKey)throw new i(`createStandards received an apiKey in a browser context. API keys belong to server code only (Route Handlers, Server Components, scripts).`);if(e.baseUrl===void 0)throw new i(`createStandards needs an explicit baseUrl in a browser context: STANDARDS_API_URL and STANDARDS_API_KEY are never read from the environment there.`);return{...e,baseUrl:e.baseUrl,apiKey:``}}let t=readEnvironment(),n=e.baseUrl??t.baseUrl;if(n===void 0)throw new i(`createStandards needs a base URL: pass baseUrl or set the STANDARDS_API_URL environment variable.`);let r=e.apiKey??t.apiKey;if(r===void 0)throw new i(`createStandards needs an API key: pass apiKey or set the STANDARDS_API_KEY environment variable.`);return{...e,baseUrl:n,apiKey:r}}function createStandards(e={}){let{bundles:t=[],transport:n,...a}=e;if(n!==void 0&&Object.values(a).some(e=>e!==void 0))throw new i(`createStandards takes a transport or an HTTP connection (baseUrl, apiKey, tenantId, timeoutMs), not both.`);return buildStandards(n??r(resolveConfig(a)),t.flatMap(e=>e.objectBuilders))}function buildStandards(e,t){let n=o(e),sync=((t,r)=>isBundleBuilder(t)?syncBundle(e,t,r):n.bundles.sync(t,r)),r={...n,bundles:{...n.bundles,sync},from:t=>createRecordsQuery(e,t),contract:n},i=t.map(e=>definitionOf(e).name);assertObjectNames(i),t.forEach((t,n)=>{r[objectKeyOf(i[n])]=createRecordsQuery(e,t)});let a=e.withCaller?.bind(e);return a!==void 0&&(r.as=e=>buildStandards(a(_(e)),t)),r}function isBundleBuilder(e){return typeof e==`object`&&!!e&&`objectBuilders`in e&&typeof e.build==`function`}export{definitionOf as a,createRecordsQuery as i,createStandards as n,readRecord as o,resolveConfig as r,syncBundle as s,buildStandards as t};
@@ -1,4 +0,0 @@
1
- /*! © 2025-2026 AND YOU CREATE SAS (RCS Paris 940 190 614). Proprietary — see LICENSE (Standards SDK License 1.0). */
2
- const e=require("./app-BUHCJ8SR.js");let t=require("@standards/schema"),n=require("@standards/schema/api");async function readInstalled(t,r){try{return await t.call(n.bundlesOperations.get,{name:r})}catch(t){if(t instanceof e.h&&t.status===404)return null;throw t}}async function syncBundle(t,r,i={}){let a=await r.build(),o=await readInstalled(t,a.name);if(o?.hash===a.hash&&o.label===a.label&&o.description===a.description&&o.uses.join(`
3
- `)===a.uses.join(`
4
- `))return{applied:!1,hash:a.hash};let s=i.resolutions&&i.resolutions.length>0?{...a,resolutions:i.resolutions}:a;try{return await t.call(n.bundlesOperations.sync,{name:a.name,bundle:s})}catch(t){throw t instanceof e.h&&t.status===409?new e.d(t.status,t.message,t.code):t instanceof e.h&&t.status===400?new e.f(t.status,t.message,t.code):t}}function objectKeyOf(e){return e.replace(/-([a-z0-9])/g,(e,t)=>t.toUpperCase())}const r=/* @__PURE__ */ new Set([`from`,`bundles`,`contract`,`as`]);function assertObjectKeys(t){let n=/* @__PURE__ */ new Map;for(let i of t){if(i.includes(`--`)||i.endsWith(`-`))throw new e.m(`Object "${i}" has a doubled or trailing hyphen, which has no client key. Rename the object.`);let t=objectKeyOf(i);if(r.has(t))throw new e.m(`Object "${i}" maps to the client key "${t}", which is reserved. Rename the object.`);let a=n.get(t);if(a!==void 0&&a!==i)throw new e.m(`Objects "${a}" and "${i}" both map to the client key "${t}". Rename one of them.`);n.set(t,i)}}function assertObjectNames(e){let n=/* @__PURE__ */ new Set;for(let r of e){if(n.has(r))throw new t.DuplicateError(`object`,r);n.add(r)}assertObjectKeys(e)}function readRecord(e,n){let{values:r,...i}=n;return(0,t.isPlainRecord)(r)?{...i,...(0,t.decodeRecordValues)(e,r)}:n}var i=class RecordsQueryImpl extends t.RecordQuery{constructor(e,t,n,r={object:t,combinator:`and`,rules:[],sorts:[]}){super(r),this.transport=e,this.objectName=t,this.definition=n}with(e){return new RecordsQueryImpl(this.transport,this.objectName,this.definition,{...this.state,...e})}body(){let e={};return this.state.search!==void 0&&(e.q=this.state.search),this.state.rules.length>0&&(e.filters={combinator:this.state.combinator,rules:this.state.rules}),this.state.sorts.length>0&&(e.sorts=this.state.sorts),this.state.limit!==void 0&&(e.limit=this.state.limit),this.state.offset!==void 0&&(e.offset=this.state.offset),e}revive(e){return readRecord(this.definition,e)}async export(t,r={}){if(!this.transport.postRaw)throw new e.m(`export() needs a transport with postRaw(path, body): Promise<Response>`);let{filters:i,sorts:a}=this.body(),{ids:o,locale:s,filename:c}=r;return await this.transport.postRaw((0,n.buildOperationPath)(n.recordsOperations.export,{objectName:this.objectName}),{q:this.state.search??``,...i?{filters:i}:{},...a?{sorts:a}:{},columns:t,...o?{ids:o}:{},...s?{locale:s}:{},timezone:r.timezone??Intl.DateTimeFormat().resolvedOptions().timeZone,...c?{filename:c}:{}})}async aggregate(e){if(this.state.search!==void 0)throw new t.AggregateValidationError(t.SchemaErrorCode.AGGREGATE_SEARCH_UNSUPPORTED,`An aggregate cannot be narrowed by a search; use filters instead`);let r={...e,query:this.toDefinition(),timezone:e.timezone??Intl.DateTimeFormat().resolvedOptions().timeZone};return await this.transport.call(n.recordsOperations.aggregate,{objectName:this.objectName,...r})}async fetchPage(){let e={objectName:this.objectName,...this.body()},t=this.state.search===void 0?await this.transport.call(n.recordsOperations.list,e):await this.transport.call(n.recordsOperations.search,e);return{records:t.data.map(e=>this.revive(e)),page:t.page}}async fetch(){let{records:e,page:t}=await this.fetchPage();return{records:e,total:t.total}}async all(){if(this.state.limit!==void 0&&this.state.limit<0)return(await this.fetch()).records;let e=this.state.limit??1/0,t=[],n=this.state.offset??0;for(;;){let r=Math.min(1e3,e-t.length);if(r<=0)return t;let{records:i,page:a}=await this.with({limit:r,offset:n}).fetchPage();if(t.push(...i),!a.hasMore)return t;let o=a.nextOffset??n+i.length;if(o<=n)return t;n=o}}async single(){let{records:e}=await this.limit(1).fetch();return e[0]??null}async get(e){let t=await this.transport.call(n.recordsOperations.get,{objectName:this.objectName,id:e});return this.revive(t)}async create(e,{allowDraft:r,metadata:i}={}){let a={...r!==void 0&&{allowDraft:r},...i!==void 0&&{metadata:i}},o=await this.transport.call(n.recordsOperations.create,{objectName:this.objectName,data:(0,t.encodeRecordValues)(this.definition,e),...Object.keys(a).length>0&&{options:a}});return this.revive(o)}async update(r,i,{metadata:a}={}){let o=(0,t.encodeRecordValues)(this.definition,i);if(a===void 0){let e=await this.transport.call(n.recordsOperations.update,{objectName:this.objectName,id:r,values:o});return this.revive(e)}let{objectId:s}=await this.transport.call(n.recordsOperations.get,{objectName:this.objectName,id:r}),{steps:c}=await this.transport.call(n.recordOperationsOperations.execute,{opId:crypto.randomUUID(),steps:[{kind:`record.set`,objectId:s,recordId:r,values:o,metadata:a}]}),[l]=c;if(l===void 0||l.status===`error`){let n=l?.code,r=n===void 0?500:t.SCHEMA_ERROR_HTTP_STATUS[n];throw e.o(r,JSON.stringify({message:l?.message,code:n}))}let u=(0,n.decodeOperationOutput)(n.recordsOperations.get,l.record);return this.revive(u)}async delete(e){await this.transport.call(n.recordsOperations.delete,{objectName:this.objectName,id:e})}async inChunks(e,t){for(let n=0;n<e.length;n+=100)await t(e.slice(n,n+100),n)}async createMany(e){let r={created:[],errors:[]};return await this.inChunks(e,async(e,i)=>{let a=await this.transport.call(n.recordsOperations.bulkCreate,{objectName:this.objectName,records:e.map(e=>(0,t.encodeRecordValues)(this.definition,e))});r.created.push(...a.created.map(e=>this.revive(e))),r.errors.push(...a.errors.map(e=>({...e,index:e.index+i})))}),r}async updateMany(e){let r={updated:[],errors:[]};return await this.inChunks(e,async e=>{let i=await this.transport.call(n.recordsOperations.bulkUpdate,{objectName:this.objectName,updates:e.map(({id:e,data:n})=>({id:e,data:(0,t.encodeRecordValues)(this.definition,n)}))});r.updated.push(...i.updated.map(e=>this.revive(e))),r.errors.push(...i.errors)}),r}async deleteMany(e){let t={deleted:[],errors:[]};return await this.inChunks(e,async e=>{let r=await this.transport.call(n.recordsOperations.bulkDelete,{objectName:this.objectName,ids:e});t.deleted.push(...r.deleted),t.errors.push(...r.errors)}),t}async listAccess(e){return await this.transport.call(n.recordAccessOperations.list,{objectName:this.objectName,recordId:e})}async grantAccess(e,t,r){return await this.transport.call(n.recordAccessOperations.grant,{objectName:this.objectName,recordId:e,actorId:t,role:r})}async revokeAccess(e,t){return await this.transport.call(n.recordAccessOperations.revoke,{objectName:this.objectName,recordId:e,actorId:t})}async clearAccess(e){return await this.transport.call(n.recordAccessOperations.clear,{objectName:this.objectName,recordId:e})}};const a=/* @__PURE__ */ new WeakMap;function definitionOf(e){let t=a.get(e);if(t)return t;let n=e.build();return a.set(e,n),n}function createRecordsQuery(e,t){if(typeof t==`string`)return new i(e,t,null);let n=definitionOf(t);return new i(e,n.name,n)}function readEnvironment(){return typeof process>`u`||!process.env?{}:{baseUrl:process.env.STANDARDS_API_URL||void 0,apiKey:process.env.STANDARDS_API_KEY||void 0}}function resolveConfig(t){if(globalThis.window!==void 0){if(t.apiKey)throw new e.m(`createStandards received an apiKey in a browser context. API keys belong to server code only (Route Handlers, Server Components, scripts).`);if(t.baseUrl===void 0)throw new e.m(`createStandards needs an explicit baseUrl in a browser context: STANDARDS_API_URL and STANDARDS_API_KEY are never read from the environment there.`);return{...t,baseUrl:t.baseUrl,apiKey:``}}let n=readEnvironment(),r=t.baseUrl??n.baseUrl;if(r===void 0)throw new e.m(`createStandards needs a base URL: pass baseUrl or set the STANDARDS_API_URL environment variable.`);let i=t.apiKey??n.apiKey;if(i===void 0)throw new e.m(`createStandards needs an API key: pass apiKey or set the STANDARDS_API_KEY environment variable.`);return{...t,baseUrl:r,apiKey:i}}function createStandards(t={}){let{bundles:n=[],transport:r,...i}=t;if(r!==void 0&&Object.values(i).some(e=>e!==void 0))throw new e.m(`createStandards takes a transport or an HTTP connection (baseUrl, apiKey, tenantId, timeoutMs), not both.`);return buildStandards(r??e.i(resolveConfig(i)),n.flatMap(e=>e.objectBuilders))}function buildStandards(t,r){let i=e.t(t),sync=((e,n)=>isBundleBuilder(e)?syncBundle(t,e,n):i.bundles.sync(e,n)),a={...i,bundles:{...i.bundles,sync},from:e=>createRecordsQuery(t,e),contract:i},o=r.map(e=>definitionOf(e).name);assertObjectNames(o),r.forEach((e,n)=>{a[objectKeyOf(o[n])]=createRecordsQuery(t,e)});let s=t.withCaller?.bind(t);return s!==void 0&&(a.as=e=>buildStandards(s((0,n.callerOf)(e)),r)),a}function isBundleBuilder(e){return typeof e==`object`&&!!e&&`objectBuilders`in e&&typeof e.build==`function`}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return definitionOf}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return createRecordsQuery}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return createStandards}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return readRecord}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return resolveConfig}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return syncBundle}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return buildStandards}});