declastruct 1.1.10 → 1.1.11

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.
@@ -2,37 +2,41 @@ import { DomainEntity, DomainLiteral, Ref, Refable, RefByPrimary, RefByUnique }
2
2
  import { HasMetadata } from 'type-fns';
3
3
  /**
4
4
  * .what = standardized data access interface for any resource type
5
+ *
5
6
  * .why = enforces idempotent semantics and consistent access patterns across all providers
6
- * .note = TResourceClass is the class constructor (e.g., typeof MyResource) with static unique/primary properties
7
+ *
8
+ * .note =
9
+ * - TResourceClass is the class constructor (e.g., typeof MyResource) with static unique/primary properties
10
+ * - uses method syntax in the get & set for bivariance, to enable assignment to DeclastructDao<any, any, any>
7
11
  */
8
12
  export interface DeclastructDao<TResource extends DomainEntity<any>, TResourceClass extends Refable<any, any, any>, TContext = never> {
9
13
  get: {
10
14
  /**
11
15
  * required - fetch by unique keys (enables idempotency)
12
16
  */
13
- byUnique: (input: RefByUnique<TResourceClass>, context: TContext) => Promise<TResource | null>;
17
+ byUnique(input: RefByUnique<TResourceClass>, context: TContext): Promise<TResource | null>;
14
18
  /**
15
19
  * optional - fetch by primary keys (if resource supports them)
16
20
  */
17
- byPrimary?: (input: RefByPrimary<TResourceClass>, context: TContext) => Promise<TResource | null>;
21
+ byPrimary?(input: RefByPrimary<TResourceClass>, context: TContext): Promise<TResource | null>;
18
22
  /**
19
23
  * required - fetch by any supported reference type
20
24
  */
21
- byRef: (input: Ref<TResourceClass>, context: TContext) => Promise<TResource | null>;
25
+ byRef(input: Ref<TResourceClass>, context: TContext): Promise<TResource | null>;
22
26
  };
23
27
  set: {
24
28
  /**
25
29
  * required - find or insert resource (idempotent create)
26
30
  */
27
- finsert: (input: TResource, context: TContext) => Promise<HasMetadata<TResource>>;
31
+ finsert(input: TResource, context: TContext): Promise<HasMetadata<TResource>>;
28
32
  /**
29
33
  * optional - create or update resource (idempotent upsert)
30
34
  */
31
- upsert?: (input: TResource, context: TContext) => Promise<HasMetadata<TResource>>;
35
+ upsert?(input: TResource, context: TContext): Promise<HasMetadata<TResource>>;
32
36
  /**
33
37
  * optional - delete resource
34
38
  */
35
- delete?: (input: Ref<TResourceClass>, context: TContext) => Promise<void>;
39
+ delete?(input: Ref<TResourceClass>, context: TContext): Promise<void>;
36
40
  };
37
41
  }
38
42
  export declare class DeclastructDao<TResource extends DomainEntity<any>, TResourceClass extends Refable<any, any, any>, TContext> extends DomainLiteral<DeclastructDao<TResource, TResourceClass, TContext>> implements DeclastructDao<TResource, TResourceClass, TContext> {
@@ -1 +1 @@
1
- {"version":3,"file":"DeclastructDao.js","sourceRoot":"","sources":["../../src/domain.objects/DeclastructDao.ts"],"names":[],"mappings":";;;AAAA,mDAOwB;AA+DxB,MAAa,cAKX,SAAQ,8BAAkE;CACT;AANnE,wCAMmE"}
1
+ {"version":3,"file":"DeclastructDao.js","sourceRoot":"","sources":["../../src/domain.objects/DeclastructDao.ts"],"names":[],"mappings":";;;AAAA,mDAOwB;AAmExB,MAAa,cAKX,SAAQ,8BAAkE;CACT;AANnE,wCAMmE"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const domain_objects_1 = require("domain-objects");
3
4
  const DeclastructProvider_1 = require("./DeclastructProvider");
4
5
  describe('DeclastructProvider', () => {
5
6
  it('should build a provider with all required properties', () => {
@@ -31,5 +32,49 @@ describe('DeclastructProvider', () => {
31
32
  });
32
33
  expect(provider).toBeDefined();
33
34
  });
35
+ describe('resource with optional primary key', () => {
36
+ class DemoResourceWithOptionalPrimary extends domain_objects_1.DomainEntity {
37
+ }
38
+ DemoResourceWithOptionalPrimary.primary = ['uuid'];
39
+ DemoResourceWithOptionalPrimary.unique = ['name'];
40
+ it('should work with daos that have optional primary keys and byPrimary defined', () => {
41
+ // define a dao for the resource with optional primary key
42
+ const demoDao = {
43
+ get: {
44
+ byUnique: async () => null,
45
+ byPrimary: async (input) => {
46
+ // input.uuid should be string (not string | undefined)
47
+ const uuid = input.uuid;
48
+ expect(uuid).toBeDefined();
49
+ return null;
50
+ },
51
+ byRef: async () => null,
52
+ },
53
+ set: {
54
+ finsert: async (r) => r,
55
+ },
56
+ };
57
+ // build provider with the dao
58
+ const provider = new DeclastructProvider_1.DeclastructProvider({
59
+ name: 'optional-primary-key-provider',
60
+ daos: {
61
+ DemoResourceWithOptionalPrimary: demoDao,
62
+ },
63
+ context: {},
64
+ hooks: {
65
+ beforeAll: async () => { },
66
+ afterAll: async () => { },
67
+ },
68
+ });
69
+ // verify provider structure
70
+ expect(provider.name).toBe('optional-primary-key-provider');
71
+ expect(provider.daos.DemoResourceWithOptionalPrimary).toBeDefined();
72
+ // access dao to verify structure
73
+ const dao = provider.daos.DemoResourceWithOptionalPrimary;
74
+ expect(dao?.get.byPrimary).toBeDefined();
75
+ expect(dao?.get.byUnique).toBeDefined();
76
+ expect(dao?.set.finsert).toBeDefined();
77
+ });
78
+ });
34
79
  });
35
80
  //# sourceMappingURL=DeclastructProvider.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DeclastructProvider.test.js","sourceRoot":"","sources":["../../src/domain.objects/DeclastructProvider.test.ts"],"names":[],"mappings":";;AAAA,+DAA4D;AAE5D,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,QAAQ,GAAG,IAAI,yCAAmB,CAAC;YACvC,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,EAAE;YACR,OAAO,EAAE,EAAE;YACX,KAAK,EAAE;gBACL,SAAS,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;gBACzB,QAAQ,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;aACzB;SACF,CAAC,CAAC;QAEH,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC5C,MAAM,CAAC,QAAQ,CAAC,IAAI,CAA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MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;wBAC3B,OAAO,IAAI,CAAC;oBACd,CAAC;oBACD,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI;iBACxB;gBACD,GAAG,EAAE;oBACH,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAQ;iBAC/B;aACF,CAAC;YAEF,8BAA8B;YAC9B,MAAM,QAAQ,GAAG,IAAI,yCAAmB,CAAC;gBACvC,IAAI,EAAE,+BAA+B;gBACrC,IAAI,EAAE;oBACJ,+BAA+B,EAAE,OAAO;iBACzC;gBACD,OAAO,EAAE,EAAE;gBACX,KAAK,EAAE;oBACL,SAAS,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;oBACzB,QAAQ,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;iBACzB;aACF,CAAC,CAAC;YAEH,4BAA4B;YAC5B,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;YAC5D,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC,WAAW,EAAE,CAAC;YAEpE,iCAAiC;YACjC,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,+BAA+B,CAAC;YAC1D,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YACzC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;YACxC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "declastruct",
3
3
  "author": "ehmpathy",
4
4
  "description": "Add declarative control to any resource constructs. Declare, plan, and apply within an observable pit-of-success.",
5
- "version": "1.1.10",
5
+ "version": "1.1.11",
6
6
  "repository": "ehmpathy/declastruct",
7
7
  "homepage": "https://github.com/ehmpathy/declastruct",
8
8
  "keywords": [