shutro 0.1.0 → 0.2.1
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 +12 -2
- package/dist/audit/index.d.ts +3 -1
- package/dist/audit/index.js +2 -0
- package/dist/cli/cli.js +17 -2
- package/dist/cli/config.js +2 -0
- package/dist/cli/generate/generate.js +2 -0
- package/dist/cli/generate/render.js +57 -8
- package/dist/cli/init.js +4 -4
- package/dist/cli/resolve.d.ts +2 -0
- package/dist/cli/resolve.js +28 -0
- package/dist/core/data/data.d.ts +59 -0
- package/dist/core/data/data.js +119 -0
- package/dist/core/data/load.d.ts +37 -0
- package/dist/core/data/load.js +236 -0
- package/dist/core/env/env.d.ts +175 -2
- package/dist/core/env/env.js +304 -19
- package/dist/core/env/identity.d.ts +10 -0
- package/dist/core/env/identity.js +16 -0
- package/dist/core/errors.d.ts +15 -1
- package/dist/core/errors.js +21 -0
- package/dist/core/events/events.d.ts +44 -0
- package/dist/core/events/events.js +58 -0
- package/dist/core/events/workers.d.ts +56 -0
- package/dist/core/events/workers.js +155 -0
- package/dist/core/index.d.ts +17 -9
- package/dist/core/index.js +11 -3
- package/dist/core/model/field.d.ts +33 -0
- package/dist/core/model/field.js +64 -1
- package/dist/core/model/generated.d.ts +4 -2
- package/dist/core/model/model.d.ts +40 -0
- package/dist/core/model/model.js +28 -0
- package/dist/core/model/related.d.ts +17 -0
- package/dist/core/model/related.js +60 -0
- package/dist/core/model/typed.d.ts +107 -0
- package/dist/core/model/typed.js +46 -0
- package/dist/core/money/fx.d.ts +10 -2
- package/dist/core/money/fx.js +17 -2
- package/dist/core/recordset/aggregate.d.ts +22 -0
- package/dist/core/recordset/aggregate.js +258 -0
- package/dist/core/recordset/audit.d.ts +9 -1
- package/dist/core/recordset/audit.js +59 -2
- package/dist/core/recordset/compute.d.ts +2 -0
- package/dist/core/recordset/compute.js +11 -2
- package/dist/core/recordset/domain.d.ts +4 -0
- package/dist/core/recordset/domain.js +74 -2
- package/dist/core/recordset/onchange.js +70 -37
- package/dist/core/recordset/recordset.d.ts +10 -1
- package/dist/core/recordset/recordset.js +80 -14
- package/dist/core/recordset/security.d.ts +15 -1
- package/dist/core/recordset/security.js +95 -10
- package/dist/core/recordset/source.d.ts +9 -0
- package/dist/core/recordset/source.js +19 -0
- package/dist/core/recordset/transitions.js +4 -1
- package/dist/core/recordset/types.d.ts +131 -12
- package/dist/core/recordset/values.d.ts +6 -0
- package/dist/core/recordset/values.js +34 -4
- package/dist/core/recordset/writes.d.ts +6 -1
- package/dist/core/recordset/writes.js +217 -12
- package/dist/core/registry/ddl.d.ts +9 -0
- package/dist/core/registry/ddl.js +49 -2
- package/dist/core/registry/module.d.ts +10 -1
- package/dist/core/registry/module.js +2 -0
- package/dist/core/registry/registry.d.ts +29 -4
- package/dist/core/registry/registry.js +100 -5
- package/dist/core/security/runtime.d.ts +102 -0
- package/dist/core/security/runtime.js +232 -0
- package/dist/driver-pg/driver.d.ts +2 -0
- package/dist/driver-pg/driver.js +1 -0
- package/dist/migrate/apply.d.ts +5 -1
- package/dist/migrate/apply.js +20 -2
- package/dist/migrate/schema.js +40 -2
- package/dist/security/index.d.ts +24 -0
- package/dist/security/index.js +16 -0
- package/dist/sql/tag.d.ts +5 -0
- package/dist/sql/tag.js +29 -1
- package/package.json +1 -1
package/dist/security/index.js
CHANGED
|
@@ -28,6 +28,22 @@ export function defineGroup(input) {
|
|
|
28
28
|
code: input.code,
|
|
29
29
|
label: input.label ?? input.code,
|
|
30
30
|
implies: Object.freeze([...(input.implies ?? [])]),
|
|
31
|
+
administrator: input.administrator === true,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** Declares a feature permission. @throws {SecurityDefinitionError} for malformed codes. */
|
|
35
|
+
export function definePermission(input) {
|
|
36
|
+
if (typeof input.code !== 'string' || !GROUP_CODE.test(input.code)) {
|
|
37
|
+
throw new SecurityDefinitionError(`${JSON.stringify(input.code)} is not a permission code.`, "Use 'module.name', e.g. 'sale.discount_approve'.");
|
|
38
|
+
}
|
|
39
|
+
for (const code of input.groups) {
|
|
40
|
+
if (!GROUP_CODE.test(code))
|
|
41
|
+
throw new SecurityDefinitionError(`Permission '${input.code}' is granted to ${JSON.stringify(code)}, which is not a group code.`, "Use 'module.name'.");
|
|
42
|
+
}
|
|
43
|
+
return Object.freeze({
|
|
44
|
+
code: input.code,
|
|
45
|
+
label: input.label ?? input.code,
|
|
46
|
+
groups: Object.freeze([...input.groups]),
|
|
31
47
|
});
|
|
32
48
|
}
|
|
33
49
|
/** The transitive closure of `codes` over `implies` (unknown codes are kept as given). */
|
package/dist/sql/tag.d.ts
CHANGED
|
@@ -31,6 +31,11 @@ export interface SqlTag {
|
|
|
31
31
|
* @throws {SqlError} `SQL_INVALID_PARAM` if `values` is not an array, `SQL_INVALID_TYPE`, or the value errors of the tag.
|
|
32
32
|
*/
|
|
33
33
|
array(values: readonly unknown[], elementType: string): SqlFragment;
|
|
34
|
+
/**
|
|
35
|
+
* A cast of an expression: `sql.cast(expr, 'numeric')` → `(expr)::numeric`. The type name is
|
|
36
|
+
* validated like `sql.param` casts. @throws {SqlError} `SQL_INVALID_TYPE` or `SQL_NOT_A_FRAGMENT`.
|
|
37
|
+
*/
|
|
38
|
+
cast(value: SqlFragment, type: string): SqlFragment;
|
|
34
39
|
/**
|
|
35
40
|
* Joins fragments with a separator (default `, `). Joining an empty list renders nothing.
|
|
36
41
|
* @throws {SqlError} `SQL_NOT_A_FRAGMENT` if an item is not a fragment.
|
package/dist/sql/tag.js
CHANGED
|
@@ -74,7 +74,35 @@ export const sql = Object.assign(tag, {
|
|
|
74
74
|
if (!Array.isArray(values)) {
|
|
75
75
|
throw new SqlError('SQL_INVALID_PARAM', `sql.array() expects an array, got ${typeof values}.`, 'Pass an array of values; use sql.param() for a single value.');
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
const type = checkType(elementType);
|
|
78
|
+
// Arrays of bytes: the driver infers `bytea` from the elements and the `bytea[]` cast then fails. They travel
|
|
79
|
+
// as hex text (`\x…`) and are cast element-wise on the server.
|
|
80
|
+
if (type === 'bytea') {
|
|
81
|
+
const hex = values.map((v) => v instanceof Uint8Array ? `\\x${Buffer.from(v).toString('hex')}` : v);
|
|
82
|
+
return fragment({
|
|
83
|
+
kind: 'seq',
|
|
84
|
+
nodes: Object.freeze([
|
|
85
|
+
Object.freeze({ kind: 'text', text: '(' }),
|
|
86
|
+
param(hex, 'text[]'),
|
|
87
|
+
Object.freeze({ kind: 'text', text: ')::bytea[]' }),
|
|
88
|
+
]),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return fragment(param(values, `${type}[]`));
|
|
92
|
+
},
|
|
93
|
+
cast(value, type) {
|
|
94
|
+
if (!isSql(value)) {
|
|
95
|
+
throw new SqlError('SQL_NOT_A_FRAGMENT', 'sql.cast() expects a sql fragment.', 'Pass an expression built with the sql tag; cast bound values with sql.param(value, type).');
|
|
96
|
+
}
|
|
97
|
+
const target = checkType(type);
|
|
98
|
+
return fragment({
|
|
99
|
+
kind: 'seq',
|
|
100
|
+
nodes: Object.freeze([
|
|
101
|
+
Object.freeze({ kind: 'text', text: '(' }),
|
|
102
|
+
value.node,
|
|
103
|
+
Object.freeze({ kind: 'text', text: `)::${target}` }),
|
|
104
|
+
]),
|
|
105
|
+
});
|
|
78
106
|
},
|
|
79
107
|
join(fragments, separator = COMMA) {
|
|
80
108
|
if (!isSql(separator)) {
|
package/package.json
CHANGED