@owlmeans/state 0.1.18-rc.8 → 0.1.18

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.
Files changed (55) hide show
  1. package/README.md +173 -68
  2. package/agent-meta/manifest.json +3 -3
  3. package/agent-meta/skills/state/SKILL.md +137 -58
  4. package/build/consts.local.d.ts +10 -0
  5. package/build/consts.local.d.ts.map +1 -0
  6. package/build/consts.local.js +10 -0
  7. package/build/consts.local.js.map +1 -0
  8. package/build/errors.d.ts +12 -5
  9. package/build/errors.d.ts.map +1 -1
  10. package/build/errors.js +16 -13
  11. package/build/errors.js.map +1 -1
  12. package/build/helper.d.ts +16 -0
  13. package/build/helper.d.ts.map +1 -0
  14. package/build/helper.js +14 -0
  15. package/build/helper.js.map +1 -0
  16. package/build/index.d.ts +3 -2
  17. package/build/index.d.ts.map +1 -1
  18. package/build/index.js +2 -2
  19. package/build/index.js.map +1 -1
  20. package/build/resource.d.ts +12 -5
  21. package/build/resource.d.ts.map +1 -1
  22. package/build/resource.js +317 -207
  23. package/build/resource.js.map +1 -1
  24. package/build/types.d.ts +91 -50
  25. package/build/types.d.ts.map +1 -1
  26. package/build/types.local.d.ts +15 -0
  27. package/build/types.local.d.ts.map +1 -0
  28. package/build/types.local.js +2 -0
  29. package/build/types.local.js.map +1 -0
  30. package/build/utils/criteria.d.ts.map +1 -1
  31. package/build/utils/criteria.js.map +1 -1
  32. package/build/utils/model.d.ts +10 -2
  33. package/build/utils/model.d.ts.map +1 -1
  34. package/build/utils/model.js +26 -22
  35. package/build/utils/model.js.map +1 -1
  36. package/build/utils/types.d.ts +15 -0
  37. package/build/utils/types.d.ts.map +1 -0
  38. package/build/utils/types.js +2 -0
  39. package/build/utils/types.js.map +1 -0
  40. package/package.json +4 -4
  41. package/src/consts.local.ts +11 -0
  42. package/src/errors.ts +16 -13
  43. package/src/helper.ts +17 -0
  44. package/src/index.ts +3 -2
  45. package/src/resource.ts +359 -241
  46. package/src/types.local.ts +16 -0
  47. package/src/types.ts +98 -55
  48. package/src/utils/model.ts +35 -28
  49. package/src/utils/types.ts +15 -0
  50. package/tests/resource.spec.ts +347 -90
  51. package/build/.gitkeep +0 -0
  52. package/src/consts.ts +0 -3
  53. package/src/utils/criteria.ts +0 -252
  54. package/src/utils/index.ts +0 -3
  55. package/tests/criteria.spec.ts +0 -121
package/build/errors.d.ts CHANGED
@@ -1,10 +1,17 @@
1
1
  import { ResourceError } from '@owlmeans/resource';
2
- export declare class StateToolingError extends ResourceError {
3
- static typeName: string;
4
- constructor(msg: string);
5
- }
6
- export declare class StateListenerError extends StateToolingError {
2
+ /**
3
+ * The resource was asked for something its {@link StateConfig} does not allow. Both cases are
4
+ * wiring mistakes rather than missing data, so they throw instead of answering with nothing.
5
+ */
6
+ export declare class StateConfigError extends ResourceError {
7
7
  static typeName: string;
8
+ /**
9
+ * A record was addressed without an id on a resource that holds many of them. Only a `single`
10
+ * resource has a record that needs no naming.
11
+ */
12
+ static readonly NonSingle: string;
13
+ /** A write carried no value for the resource's id field, and nothing here mints one. */
14
+ static readonly NoId: string;
8
15
  constructor(msg: string);
9
16
  }
10
17
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,qBAAa,iBAAkB,SAAQ,aAAa;IAClD,OAAuB,QAAQ,SAAqC;IAEpE,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF;AAED,qBAAa,kBAAmB,SAAQ,iBAAiB;IACvD,OAAuB,QAAQ,SAA0C;IAEzE,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,OAAuB,QAAQ,SAAyC;IAExE;;;OAGG;IACH,gBAAuB,SAAS,EAAE,MAAM,CAAe;IAEvD,wFAAwF;IACxF,gBAAuB,IAAI,EAAE,MAAM,CAAU;IAE7C,YAAY,GAAG,EAAE,MAAM,EAGtB;CACF"}
package/build/errors.js CHANGED
@@ -1,18 +1,21 @@
1
1
  import { ResourceError } from '@owlmeans/resource';
2
- export class StateToolingError extends ResourceError {
3
- static typeName = `${ResourceError.typeName}Tooling`;
2
+ /**
3
+ * The resource was asked for something its {@link StateConfig} does not allow. Both cases are
4
+ * wiring mistakes rather than missing data, so they throw instead of answering with nothing.
5
+ */
6
+ export class StateConfigError extends ResourceError {
7
+ static typeName = `${ResourceError.typeName}StateConfig`;
8
+ /**
9
+ * A record was addressed without an id on a resource that holds many of them. Only a `single`
10
+ * resource has a record that needs no naming.
11
+ */
12
+ static NonSingle = 'non-single';
13
+ /** A write carried no value for the resource's id field, and nothing here mints one. */
14
+ static NoId = 'no-id';
4
15
  constructor(msg) {
5
- super(`tooling:${msg}`);
6
- this.type = StateToolingError.typeName;
16
+ super(`state-config:${msg}`);
17
+ this.type = StateConfigError.typeName;
7
18
  }
8
19
  }
9
- export class StateListenerError extends StateToolingError {
10
- static typeName = `${StateToolingError.typeName}Listener`;
11
- constructor(msg) {
12
- super(`listener:${msg}`);
13
- this.type = StateListenerError.typeName;
14
- }
15
- }
16
- ResourceError.registerErrorClass(StateToolingError);
17
- ResourceError.registerErrorClass(StateListenerError);
20
+ ResourceError.registerErrorClass(StateConfigError);
18
21
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IAC3C,MAAM,CAAU,QAAQ,GAAG,GAAG,aAAa,CAAC,QAAQ,SAAS,CAAA;IAEpE,YAAY,GAAW;QACrB,KAAK,CAAC,WAAW,GAAG,EAAE,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC,QAAQ,CAAA;IACxC,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,iBAAiB;IAChD,MAAM,CAAU,QAAQ,GAAG,GAAG,iBAAiB,CAAC,QAAQ,UAAU,CAAA;IAEzE,YAAY,GAAW;QACrB,KAAK,CAAC,YAAY,GAAG,EAAE,CAAC,CAAA;QACxB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC,QAAQ,CAAA;IACzC,CAAC;CACF;AAED,aAAa,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,CAAA;AACnD,aAAa,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAA"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IAC1C,MAAM,CAAU,QAAQ,GAAG,GAAG,aAAa,CAAC,QAAQ,aAAa,CAAA;IAExE;;;OAGG;IACI,MAAM,CAAU,SAAS,GAAW,YAAY,CAAA;IAEvD,wFAAwF;IACjF,MAAM,CAAU,IAAI,GAAW,OAAO,CAAA;IAE7C,YAAY,GAAW;QACrB,KAAK,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC,QAAQ,CAAA;IACvC,CAAC;CACF;AAED,aAAa,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAA"}
@@ -0,0 +1,16 @@
1
+ import type { ResourceRecord } from '@owlmeans/resource';
2
+ import type { StateAlias } from './types.js';
3
+ /**
4
+ * Name a state resource once, with the record type it holds attached:
5
+ *
6
+ * ```typescript
7
+ * export const TASKS = stateAlias<Task>('tasks')
8
+ * const tasks = context.getStateResource(TASKS) // StateResource<Task>
9
+ * ```
10
+ *
11
+ * The handle is the string itself at runtime — the type rides along only so that every reader of
12
+ * the alias gets the record type without repeating it, and so that a mismatch is a compile error
13
+ * instead of a record shaped like nothing anyone expected.
14
+ */
15
+ export declare const stateAlias: <T extends ResourceRecord>(alias: string) => StateAlias<T>;
16
+ //# sourceMappingURL=helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,cAAc,SAAS,MAAM,KAAG,UAAU,CAAC,CAAC,CACzD,CAAA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Name a state resource once, with the record type it holds attached:
3
+ *
4
+ * ```typescript
5
+ * export const TASKS = stateAlias<Task>('tasks')
6
+ * const tasks = context.getStateResource(TASKS) // StateResource<Task>
7
+ * ```
8
+ *
9
+ * The handle is the string itself at runtime — the type rides along only so that every reader of
10
+ * the alias gets the record type without repeating it, and so that a mismatch is a compile error
11
+ * instead of a record shaped like nothing anyone expected.
12
+ */
13
+ export const stateAlias = (alias) => alias;
14
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAA2B,KAAa,EAAiB,EAAE,CACnF,KAAsB,CAAA"}
package/build/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export type * from './types.js';
2
- export * from './consts.js';
3
2
  export * from './errors.js';
3
+ export * from './helper.js';
4
4
  export * from './resource.js';
5
- export * from './utils/criteria.js';
5
+ export * from './utils/model.js';
6
+ export type * from './utils/types.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAE/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAE/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,mBAAmB,kBAAkB,CAAA"}
package/build/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export * from './consts.js';
2
1
  export * from './errors.js';
2
+ export * from './helper.js';
3
3
  export * from './resource.js';
4
- export * from './utils/criteria.js';
4
+ export * from './utils/model.js';
5
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
@@ -1,6 +1,13 @@
1
- import type { ResourceRecord } from '@owlmeans/resource';
2
- import type { StateResource, StateResourceAppend } from './types.js';
3
- import type { BasicContext as Context, BasicConfig as Config } from '@owlmeans/context';
4
- export declare const createStateResource: <R extends ResourceRecord>(alias?: string) => StateResource<R>;
5
- export declare const appendStateResource: <C extends Config, T extends Context<C>>(ctx: T, alias?: string) => T & StateResourceAppend;
1
+ import { type BasicConfig as Config, type BasicContext as Context } from '@owlmeans/context';
2
+ import { type ResourceRecord } from '@owlmeans/resource';
3
+ import type { StateConfig, StateResource, StateResourceAppend } from './types.js';
4
+ export declare const createStateResource: <T extends ResourceRecord>(alias?: string, cfg?: StateConfig<T>) => StateResource<T>;
5
+ /**
6
+ * Register a state resource on the context and expose `getStateResource`.
7
+ *
8
+ * Idempotent: appending the same alias twice keeps the resource that is already there, so a
9
+ * setup that runs more than once does not drop what the store has collected. The first alias
10
+ * appended is the one `getStateResource()` answers with when it is called without one.
11
+ */
12
+ export declare const appendStateResource: <C extends Config, T extends Context<C>, R extends ResourceRecord = ResourceRecord>(ctx: T, alias?: string, cfg?: StateConfig<R>) => T & StateResourceAppend;
6
13
  //# sourceMappingURL=resource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA8C,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACpG,OAAO,KAAK,EAA6B,aAAa,EAAE,mBAAmB,EAA2B,MAAM,YAAY,CAAA;AAKxH,OAAO,KAAK,EAAE,YAAY,IAAI,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAEvF,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,cAAc,UAAS,MAAM,KAAmB,aAAa,CAAC,CAAC,CAsT5G,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,OACnE,CAAC,UAAS,MAAM,KACpB,CAAC,GAAG,mBAWN,CAAA"}
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,WAAW,IAAI,MAAM,EAAE,KAAK,YAAY,IAAI,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC9G,OAAO,EAAqI,KAAK,cAAc,EAAwE,MAAM,oBAAoB,CAAA;AAGjQ,OAAO,KAAK,EACV,WAAW,EAA0B,aAAa,EAAE,mBAAmB,EACxE,MAAM,YAAY,CAAA;AAQnB,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,cAAc,UACnD,MAAM,QAAgB,WAAW,CAAC,CAAC,CAAC,KAC1C,aAAa,CAAC,CAAC,CA8ZjB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC9B,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,cAAc,GAAG,cAAc,OAC5E,CAAC,UAAS,MAAM,QAAgB,WAAW,CAAC,CAAC,CAAC,KAAG,CAAC,GAAG,mBAa3D,CAAA"}