declastruct 1.4.4 → 1.5.0
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/dist/contract/sdk/index.d.ts +2 -0
- package/dist/contract/sdk/index.js +6 -1
- package/dist/contract/sdk/index.js.map +1 -1
- package/dist/domain.objects/DeclastructDao.d.ts +66 -13
- package/dist/domain.objects/DeclastructDao.js.map +1 -1
- package/dist/domain.operations/plan/planChanges.js +1 -1
- package/dist/domain.operations/plan/planChanges.js.map +1 -1
- package/dist/domain.operations/ref/getRefByPrimary.d.ts +12 -0
- package/dist/domain.operations/ref/getRefByPrimary.js +31 -0
- package/dist/domain.operations/ref/getRefByPrimary.js.map +1 -0
- package/dist/domain.operations/ref/getRefByUnique.d.ts +12 -0
- package/dist/domain.operations/ref/getRefByUnique.js +34 -0
- package/dist/domain.operations/ref/getRefByUnique.js.map +1 -0
- package/package.json +3 -3
|
@@ -4,3 +4,5 @@ export { DeclastructDao } from '../../domain.objects/DeclastructDao';
|
|
|
4
4
|
export { DeclastructPlan } from '../../domain.objects/DeclastructPlan';
|
|
5
5
|
export { DeclastructProvider } from '../../domain.objects/DeclastructProvider';
|
|
6
6
|
export type { IsoTimestamp } from '../../domain.objects/IsoTimestamp';
|
|
7
|
+
export { getRefByPrimary } from '../../domain.operations/ref/getRefByPrimary';
|
|
8
|
+
export { getRefByUnique } from '../../domain.operations/ref/getRefByUnique';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// domain objects
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.DeclastructProvider = exports.DeclastructPlan = exports.DeclastructDao = exports.DeclastructChangeAction = exports.DeclastructChange = void 0;
|
|
4
|
+
exports.getRefByUnique = exports.getRefByPrimary = exports.DeclastructProvider = exports.DeclastructPlan = exports.DeclastructDao = exports.DeclastructChangeAction = exports.DeclastructChange = void 0;
|
|
5
5
|
var DeclastructChange_1 = require("../../domain.objects/DeclastructChange");
|
|
6
6
|
Object.defineProperty(exports, "DeclastructChange", { enumerable: true, get: function () { return DeclastructChange_1.DeclastructChange; } });
|
|
7
7
|
Object.defineProperty(exports, "DeclastructChangeAction", { enumerable: true, get: function () { return DeclastructChange_1.DeclastructChangeAction; } });
|
|
@@ -11,4 +11,9 @@ var DeclastructPlan_1 = require("../../domain.objects/DeclastructPlan");
|
|
|
11
11
|
Object.defineProperty(exports, "DeclastructPlan", { enumerable: true, get: function () { return DeclastructPlan_1.DeclastructPlan; } });
|
|
12
12
|
var DeclastructProvider_1 = require("../../domain.objects/DeclastructProvider");
|
|
13
13
|
Object.defineProperty(exports, "DeclastructProvider", { enumerable: true, get: function () { return DeclastructProvider_1.DeclastructProvider; } });
|
|
14
|
+
// domain operations
|
|
15
|
+
var getRefByPrimary_1 = require("../../domain.operations/ref/getRefByPrimary");
|
|
16
|
+
Object.defineProperty(exports, "getRefByPrimary", { enumerable: true, get: function () { return getRefByPrimary_1.getRefByPrimary; } });
|
|
17
|
+
var getRefByUnique_1 = require("../../domain.operations/ref/getRefByUnique");
|
|
18
|
+
Object.defineProperty(exports, "getRefByUnique", { enumerable: true, get: function () { return getRefByUnique_1.getRefByUnique; } });
|
|
14
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/sdk/index.ts"],"names":[],"mappings":";AAAA,iBAAiB;;;AAGjB,4EAGgD;AAF9C,sHAAA,iBAAiB,OAAA;AACjB,4HAAA,uBAAuB,OAAA;AAEzB,sEAAqE;AAA5D,gHAAA,cAAc,OAAA;AACvB,wEAAuE;AAA9D,kHAAA,eAAe,OAAA;AACxB,gFAA+E;AAAtE,0HAAA,mBAAmB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/sdk/index.ts"],"names":[],"mappings":";AAAA,iBAAiB;;;AAGjB,4EAGgD;AAF9C,sHAAA,iBAAiB,OAAA;AACjB,4HAAA,uBAAuB,OAAA;AAEzB,sEAAqE;AAA5D,gHAAA,cAAc,OAAA;AACvB,wEAAuE;AAA9D,kHAAA,eAAe,OAAA;AACxB,gFAA+E;AAAtE,0HAAA,mBAAmB,OAAA;AAG5B,oBAAoB;AACpB,+EAA8E;AAArE,kHAAA,eAAe,OAAA;AACxB,6EAA4E;AAAnE,gHAAA,cAAc,OAAA"}
|
|
@@ -10,33 +10,86 @@ import type { HasMetadata } from 'type-fns';
|
|
|
10
10
|
* - uses method syntax in the get & set for bivariance, to enable assignment to DeclastructDao<any, any, any>
|
|
11
11
|
*/
|
|
12
12
|
export interface DeclastructDao<TResource extends DomainEntity<any>, TResourceClass extends Refable<any, any, any>, TContext = never> {
|
|
13
|
+
/**
|
|
14
|
+
* .what = the domain object class this dao operates on
|
|
15
|
+
* .why = enables downstream operations (like getRefByPrimary) to access static properties
|
|
16
|
+
*/
|
|
17
|
+
dobj: TResourceClass;
|
|
18
|
+
/**
|
|
19
|
+
* .what = read operations for fetching resources and resolving refs
|
|
20
|
+
* .why = provides consistent, type-safe access to remote state
|
|
21
|
+
*/
|
|
13
22
|
get: {
|
|
14
23
|
/**
|
|
15
|
-
*
|
|
24
|
+
* .what = fetch a single resource by reference
|
|
25
|
+
* .why = enables looking up current state of a resource
|
|
16
26
|
*/
|
|
17
|
-
|
|
27
|
+
one: {
|
|
28
|
+
/**
|
|
29
|
+
* .what = fetch by unique keys
|
|
30
|
+
* .why = enables idempotent lookups via natural keys
|
|
31
|
+
*/
|
|
32
|
+
byUnique(input: RefByUnique<TResourceClass>, context: TContext): Promise<TResource | null>;
|
|
33
|
+
/**
|
|
34
|
+
* .what = fetch by primary keys
|
|
35
|
+
* .why = enables efficient lookups when primary key is known
|
|
36
|
+
*
|
|
37
|
+
* .note = set to null if resource lacks primary keys (forces explicit decision)
|
|
38
|
+
*/
|
|
39
|
+
byPrimary: null | ((input: RefByPrimary<TResourceClass>, context: TContext) => Promise<TResource | null>);
|
|
40
|
+
/**
|
|
41
|
+
* .what = fetch by any supported reference type
|
|
42
|
+
* .why = enables flexible lookups when ref type is not known at compile time
|
|
43
|
+
*/
|
|
44
|
+
byRef(input: Ref<TResourceClass>, context: TContext): Promise<TResource | null>;
|
|
45
|
+
};
|
|
18
46
|
/**
|
|
19
|
-
*
|
|
47
|
+
* .what = ref resolution utilities for converting between ref types
|
|
48
|
+
* .why = enables working with generic Ref<T> while resolving to specific RefByPrimary/RefByUnique when needed
|
|
49
|
+
*
|
|
50
|
+
* .note = set methods to null if resource lacks primary keys (forces explicit decision)
|
|
20
51
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
52
|
+
ref: {
|
|
53
|
+
/**
|
|
54
|
+
* .what = resolve any ref to RefByPrimary
|
|
55
|
+
* .why = enables getting primary key from any ref type
|
|
56
|
+
*
|
|
57
|
+
* .note = set to null if resource lacks primary keys
|
|
58
|
+
*/
|
|
59
|
+
byPrimary: null | ((input: Ref<TResourceClass>, context: TContext) => Promise<RefByPrimary<TResourceClass>>);
|
|
60
|
+
/**
|
|
61
|
+
* .what = resolve any ref to RefByUnique
|
|
62
|
+
* .why = enables getting unique key from any ref type
|
|
63
|
+
*
|
|
64
|
+
* .note = set to null if resource lacks primary keys
|
|
65
|
+
*/
|
|
66
|
+
byUnique: null | ((input: Ref<TResourceClass>, context: TContext) => Promise<RefByUnique<TResourceClass>>);
|
|
67
|
+
};
|
|
26
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* .what = write operations for mutating resources
|
|
71
|
+
* .why = provides idempotent, type-safe mutations to remote state
|
|
72
|
+
*/
|
|
27
73
|
set: {
|
|
28
74
|
/**
|
|
29
|
-
*
|
|
75
|
+
* .what = find or insert resource
|
|
76
|
+
* .why = idempotent create - returns existing if found by unique keys, otherwise creates
|
|
30
77
|
*/
|
|
31
78
|
finsert(input: TResource, context: TContext): Promise<HasMetadata<TResource>>;
|
|
32
79
|
/**
|
|
33
|
-
*
|
|
80
|
+
* .what = create or update resource
|
|
81
|
+
* .why = idempotent upsert - creates if not found, updates if found
|
|
82
|
+
*
|
|
83
|
+
* .note = set to null if resource does not support updates
|
|
34
84
|
*/
|
|
35
|
-
upsert
|
|
85
|
+
upsert: null | ((input: TResource, context: TContext) => Promise<HasMetadata<TResource>>);
|
|
36
86
|
/**
|
|
37
|
-
*
|
|
87
|
+
* .what = delete resource
|
|
88
|
+
* .why = removes resource from remote state
|
|
89
|
+
*
|
|
90
|
+
* .note = set to null if resource does not support deletion
|
|
38
91
|
*/
|
|
39
|
-
delete
|
|
92
|
+
delete: null | ((input: Ref<TResourceClass>, context: TContext) => Promise<void>);
|
|
40
93
|
};
|
|
41
94
|
}
|
|
42
95
|
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;
|
|
1
|
+
{"version":3,"file":"DeclastructDao.js","sourceRoot":"","sources":["../../src/domain.objects/DeclastructDao.ts"],"names":[],"mappings":";;;AAAA,mDAOwB;AA2IxB,MAAa,cAKX,SAAQ,8BAAkE;CACT;AANnE,wCAMmE"}
|
|
@@ -37,7 +37,7 @@ const planChanges = async (input, context) => {
|
|
|
37
37
|
// fetch current remote state using provider context with spinner
|
|
38
38
|
const { result: remoteState, durationMs } = await (0, withSpinner_1.withSpinner)({
|
|
39
39
|
message: 'inflight',
|
|
40
|
-
operation: () => dao.get.byUnique(resource, providerContext),
|
|
40
|
+
operation: () => dao.get.one.byUnique(resource, providerContext),
|
|
41
41
|
});
|
|
42
42
|
// log done (replaces spinner)
|
|
43
43
|
const durationSec = (durationMs / 1000).toFixed(2);
|
|
@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AM,CAAC,MAAM,KAAK,2CAAuB,CAAC,IAAI,CAC3D,CAAC;IACF,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IAChD,CAAC;IAED,cAAc;IACd,OAAO,IAAI,iCAAe,CAAC;QACzB,IAAI,EAAE,IAAA,yBAAW,EAAC,OAAO,CAAC;QAC1B,SAAS,EAAE,IAAA,+BAAc,EAAC,IAAI,IAAI,EAAE,CAAC;QACrC,IAAI,EAAE;YACJ,GAAG,EAAE,KAAK,CAAC,YAAY;SACxB;QACD,OAAO;KACR,CAAC,CAAC;AACL,CAAC,CAAC;AAnFW,QAAA,WAAW,eAmFtB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DomainEntity, type Ref, type Refable, type RefByPrimary } from 'domain-objects';
|
|
2
|
+
import type { DeclastructDao } from '../../domain.objects/DeclastructDao';
|
|
3
|
+
/**
|
|
4
|
+
* .what = resolves any ref to RefByPrimary
|
|
5
|
+
* .why = enables getting primary key from any ref type
|
|
6
|
+
* .note = if ref is already RefByPrimary, returns as-is without db call
|
|
7
|
+
*/
|
|
8
|
+
export declare const getRefByPrimary: <TResource extends DomainEntity<any>, TResourceClass extends Refable<any, any, any>, TContext extends Record<string, any>>(input: {
|
|
9
|
+
ref: Ref<TResourceClass>;
|
|
10
|
+
}, context: {
|
|
11
|
+
dao: DeclastructDao<TResource, TResourceClass, TContext>;
|
|
12
|
+
} & TContext) => Promise<RefByPrimary<TResourceClass>>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRefByPrimary = void 0;
|
|
4
|
+
const domain_objects_1 = require("domain-objects");
|
|
5
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
6
|
+
/**
|
|
7
|
+
* .what = resolves any ref to RefByPrimary
|
|
8
|
+
* .why = enables getting primary key from any ref type
|
|
9
|
+
* .note = if ref is already RefByPrimary, returns as-is without db call
|
|
10
|
+
*/
|
|
11
|
+
const getRefByPrimary = async (input, context) => {
|
|
12
|
+
// if already RefByPrimary, return as-is without db call
|
|
13
|
+
if ((0, domain_objects_1.isRefByPrimary)({ of: context.dao.dobj })(input.ref))
|
|
14
|
+
return input.ref;
|
|
15
|
+
// if RefByUnique, fetch resource and extract primary key
|
|
16
|
+
if ((0, domain_objects_1.isRefByUnique)({ of: context.dao.dobj })(input.ref)) {
|
|
17
|
+
// fetch the resource by unique key
|
|
18
|
+
const resource = await context.dao.get.one.byUnique(input.ref, context);
|
|
19
|
+
// throw if resource not found
|
|
20
|
+
if (!resource)
|
|
21
|
+
throw new helpful_errors_1.BadRequestError('resource not found by unique ref', {
|
|
22
|
+
ref: input.ref,
|
|
23
|
+
});
|
|
24
|
+
// extract primary key from the resource
|
|
25
|
+
return (0, domain_objects_1.refByPrimary)(resource);
|
|
26
|
+
}
|
|
27
|
+
// otherwise, unexpected ref type
|
|
28
|
+
throw new helpful_errors_1.UnexpectedCodePathError('invalid ref type', { ref: input.ref });
|
|
29
|
+
};
|
|
30
|
+
exports.getRefByPrimary = getRefByPrimary;
|
|
31
|
+
//# sourceMappingURL=getRefByPrimary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRefByPrimary.js","sourceRoot":"","sources":["../../../src/domain.operations/ref/getRefByPrimary.ts"],"names":[],"mappings":";;;AAAA,mDAQwB;AACxB,mDAA0E;AAI1E;;;;GAIG;AACI,MAAM,eAAe,GAAG,KAAK,EAKlC,KAEC,EACD,OAEY,EAC2B,EAAE;IACzC,wDAAwD;IACxD,IAAI,IAAA,+BAAc,EAAC,EAAE,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC;IAE1E,yDAAyD;IACzD,IAAI,IAAA,8BAAa,EAAC,EAAE,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACvD,mCAAmC;QACnC,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAExE,8BAA8B;QAC9B,IAAI,CAAC,QAAQ;YACX,MAAM,IAAI,gCAAe,CAAC,kCAAkC,EAAE;gBAC5D,GAAG,EAAE,KAAK,CAAC,GAAG;aACf,CAAC,CAAC;QAEL,wCAAwC;QACxC,OAAO,IAAA,6BAAY,EACjB,QAAwC,CACzC,CAAC;IACJ,CAAC;IAED,iCAAiC;IACjC,MAAM,IAAI,wCAAuB,CAAC,kBAAkB,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;AAC5E,CAAC,CAAC;AAlCW,QAAA,eAAe,mBAkC1B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DomainEntity, type Ref, type Refable, type RefByUnique } from 'domain-objects';
|
|
2
|
+
import type { DeclastructDao } from '../../domain.objects/DeclastructDao';
|
|
3
|
+
/**
|
|
4
|
+
* .what = resolves any ref to RefByUnique
|
|
5
|
+
* .why = enables getting unique key from any ref type
|
|
6
|
+
* .note = if ref is already RefByUnique, returns as-is without db call
|
|
7
|
+
*/
|
|
8
|
+
export declare const getRefByUnique: <TResource extends DomainEntity<any>, TResourceClass extends Refable<any, any, any>, TContext extends Record<string, any>>(input: {
|
|
9
|
+
ref: Ref<TResourceClass>;
|
|
10
|
+
}, context: {
|
|
11
|
+
dao: DeclastructDao<TResource, TResourceClass, TContext>;
|
|
12
|
+
} & TContext) => Promise<RefByUnique<TResourceClass>>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRefByUnique = void 0;
|
|
4
|
+
const domain_objects_1 = require("domain-objects");
|
|
5
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
6
|
+
/**
|
|
7
|
+
* .what = resolves any ref to RefByUnique
|
|
8
|
+
* .why = enables getting unique key from any ref type
|
|
9
|
+
* .note = if ref is already RefByUnique, returns as-is without db call
|
|
10
|
+
*/
|
|
11
|
+
const getRefByUnique = async (input, context) => {
|
|
12
|
+
// if already RefByUnique, return as-is without db call
|
|
13
|
+
if ((0, domain_objects_1.isRefByUnique)({ of: context.dao.dobj })(input.ref))
|
|
14
|
+
return input.ref;
|
|
15
|
+
// if RefByPrimary, fetch resource and extract unique key
|
|
16
|
+
if ((0, domain_objects_1.isRefByPrimary)({ of: context.dao.dobj })(input.ref)) {
|
|
17
|
+
// verify dao supports byPrimary
|
|
18
|
+
if (!context.dao.get.one.byPrimary)
|
|
19
|
+
throw new helpful_errors_1.UnexpectedCodePathError('dao does not support byPrimary lookup', { ref: input.ref });
|
|
20
|
+
// fetch the resource by primary key
|
|
21
|
+
const resource = await context.dao.get.one.byPrimary(input.ref, context);
|
|
22
|
+
// throw if resource not found
|
|
23
|
+
if (!resource)
|
|
24
|
+
throw new helpful_errors_1.BadRequestError('resource not found by primary ref', {
|
|
25
|
+
ref: input.ref,
|
|
26
|
+
});
|
|
27
|
+
// extract unique key from the resource
|
|
28
|
+
return (0, domain_objects_1.refByUnique)(resource);
|
|
29
|
+
}
|
|
30
|
+
// otherwise, unexpected ref type
|
|
31
|
+
throw new helpful_errors_1.UnexpectedCodePathError('invalid ref type', { ref: input.ref });
|
|
32
|
+
};
|
|
33
|
+
exports.getRefByUnique = getRefByUnique;
|
|
34
|
+
//# sourceMappingURL=getRefByUnique.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRefByUnique.js","sourceRoot":"","sources":["../../../src/domain.operations/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|
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.
|
|
5
|
+
"version": "1.5.0",
|
|
6
6
|
"repository": "ehmpathy/declastruct",
|
|
7
7
|
"homepage": "https://github.com/ehmpathy/declastruct",
|
|
8
8
|
"keywords": [
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"esbuild-register": "3.6.0",
|
|
88
88
|
"husky": "8.0.3",
|
|
89
89
|
"jest": "30.2.0",
|
|
90
|
-
"rhachet": "1.12.
|
|
91
|
-
"rhachet-roles-ehmpathy": "1.
|
|
90
|
+
"rhachet": "1.12.3",
|
|
91
|
+
"rhachet-roles-ehmpathy": "1.12.0",
|
|
92
92
|
"test-fns": "1.7.2",
|
|
93
93
|
"tsx": "4.20.6",
|
|
94
94
|
"typescript": "5.4.5"
|