@toolproof-npm/schema 0.1.76 → 0.1.78

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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { WorkStepIdentity, BranchStepIdentity, ForStepIdentity, WhileStepIdentity } from './scripts/brandFactories.js';
1
+ import { WorkStepIdentity, BranchStepIdentity, WhileStepIdentity, ForStepIdentity } from './genesis/generated/types/types.js';
2
2
  export { default as SchemaGenesis } from './genesis/generated/schemas/Genesis.js';
3
3
  export { default as SchemaJob } from './genesis/generated/schemas/Job.js';
4
4
  export { default as ResourceTypeGenesis } from './genesis/generated/resource-type-envelopes/Genesis.js';
@@ -14,4 +14,3 @@ export type { Resource_StrategyRun as Resource_StrategyRunJson } from './genesis
14
14
  export type StepIdentityJson = WorkStepIdentity | BranchStepIdentity | WhileStepIdentity | ForStepIdentity;
15
15
  export type { Documented as DocumentedJson, ResourceFormatIdentity as ResourceFormatIdentityJson, ResourceFormat as ResourceFormatJson, ExtractionSchema as ExtractionSchemaJson, IdentityProp as IdentityPropJson, MeritProp as MeritPropJson, ResourceTypeIdentity as ResourceTypeIdentityJson, ResourceType as ResourceTypeJson, ResourceRoleIdentity as ResourceRoleIdentityJson, ResourceRoleValue as ResourceRoleValueJson, ExecutionIdentity as ExecutionIdentityJson, Execution as ExecutionJson, Conditional as ConditionalJson, RoleMap as RoleMapJson, Roles as RolesJson, RoleBindingMap as RoleBindingMapJson, RoleBindings as RoleBindingsJson, ResourceIdentity as ResourceIdentityJson, WorkStepIdentity as WorkStepIdentityJson, BranchStepIdentity as BranchStepIdentityJson, WhileStepIdentity as WhileStepIdentityJson, ForStepIdentity as ForStepIdentityJson, WorkStep as WorkStepJson, BranchStep as BranchStepJson, WhileStep as WhileStepJson, ForStep as ForStepJson, StepKind as StepKindJson, Step as StepJson, CreationContext as CreationContextJson, ResourceMissing as ResourceMissingJson, ResourcePotentialInput as ResourcePotentialInputJson, ResourcePotentialOutput as ResourcePotentialOutputJson, ResourceMetaBase as ResourceMetaJson, // ATTENTION: type not generated for ResourceMeta
16
16
  Resource as ResourceJson, StrategyState as StrategyStateJson, StatelessStrategyIdentity as StatelessStrategyIdentityJson, StatelessStrategy as StatelessStrategyJson, StatefulStrategyIdentity as StatefulStrategyIdentityJson, StatefulStrategy as StatefulStrategyJson, StrategyRunIdentity as StrategyRunIdentityJson, StrategyRunStatus as StrategyRunStatusJson, StrategyRun as StrategyRunJson, StrategyRunUpdate as StrategyRunUpdateJson, JobIdentity as JobIdentityJson, Job as JobJson, JsonData as JsonDataJson, StrategyThreadIdentity as StrategyThreadIdentityJson, StrategyThreadMap as StrategyThreadMapJson, ExecutionSocket as ExecutionSocketJson, ExecutionSocketMaterialized as ExecutionSocketMaterializedJson, Timestamp as TimestampJson, } from './genesis/generated/types/types.js';
17
- export { unsafeBrand, asResourceTypeIdentity, asResourceRoleIdentity, asExecutionIdentity, asResourceIdentity, asWorkStepIdentity, asBranchStepIdentity, asForStepIdentity, asResourceFormatIdentity, asWhileStepIdentity, asStatelessStrategyIdentity, asStatefulStrategyIdentity, asResourceTypeIdentities, asResourceRoleIdentities, asExecutionIdentities, asResourceIdentities, asWorkStepIdentities, asBranchStepIdentities, asForStepIdentities, asResourceFormatIdentities, asWhileStepIdentities, asStatelessStrategyIdentities, asStatefulStrategyIdentities, } from './scripts/brandFactories.js';
package/dist/index.js CHANGED
@@ -4,5 +4,3 @@ export { default as SchemaJob } from './genesis/generated/schemas/Job.js';
4
4
  export { default as ResourceTypeGenesis } from './genesis/generated/resource-type-envelopes/Genesis.js';
5
5
  export { default as dependencies } from './genesis/generated/dependencies_ordered.json';
6
6
  export { default as terminals } from './genesis/generated/terminals.json';
7
- // Re-export brand factories so consumers can construct branded identities at runtime.
8
- export { unsafeBrand, asResourceTypeIdentity, asResourceRoleIdentity, asExecutionIdentity, asResourceIdentity, asWorkStepIdentity, asBranchStepIdentity, asForStepIdentity, asResourceFormatIdentity, asWhileStepIdentity, asStatelessStrategyIdentity, asStatefulStrategyIdentity, asResourceTypeIdentities, asResourceRoleIdentities, asExecutionIdentities, asResourceIdentities, asWorkStepIdentities, asBranchStepIdentities, asForStepIdentities, asResourceFormatIdentities, asWhileStepIdentities, asStatelessStrategyIdentities, asStatefulStrategyIdentities, } from './scripts/brandFactories.js';
@@ -45,7 +45,7 @@ async function main() {
45
45
  // IMPORTANT:
46
46
  // We intentionally do NOT re-run json-schema-to-typescript here.
47
47
  // That path produces self-contained types that degrade schema-patterned identities/refs
48
- // into plain `string`, which then becomes incompatible with our canonical branded
48
+ // into plain `string`, which then becomes incompatible with our canonical
49
49
  // identity types in `types.d.ts` (e.g. `ResourceIdentity = `RESOURCE-${string}``).
50
50
  //
51
51
  // Instead, we generate a tiny module that composes the canonical types:
@@ -459,11 +459,7 @@ async function main() {
459
459
  }
460
460
  const patternTemplates = loadPatternTemplates();
461
461
  // Replace any exported Identity/Ref aliases to use the inferred template literals where available.
462
- // Handle both `= string;` and any pre-existing branded alias `= Branded<string, 'X'>;`.
463
- ts = ts.replace(/^(export\s+type\s+)([A-Za-z_][A-Za-z0-9_]*(?:Identity|Ref))(\s*=\s*)Branded<string,\s*'[^']+'>\s*;$/gm, (_m, p1, typeName, p3) => {
464
- const tmpl = patternTemplates[typeName];
465
- return `${p1}${typeName}${p3}${tmpl ?? 'string'};`;
466
- });
462
+ // Handle the common `= string;` output from json-schema-to-typescript.
467
463
  ts = ts.replace(/^(export\s+type\s+)([A-Za-z_][A-Za-z0-9_]*(?:Identity|Ref))(\s*=\s*)string\s*;$/gm, (_m, p1, typeName, p3) => {
468
464
  const tmpl = patternTemplates[typeName];
469
465
  return `${p1}${typeName}${p3}${tmpl ?? 'string'};`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolproof-npm/schema",
3
- "version": "0.1.76",
3
+ "version": "0.1.78",
4
4
  "description": "JSON schemas and TypeScript types for ToolProof",
5
5
  "keywords": [
6
6
  "toolproof",
@@ -1,39 +0,0 @@
1
- type Brand<K extends string> = string & {
2
- readonly __brand: K;
3
- };
4
- export type ExecutionIdentity = Brand<'ExecutionIdentity'>;
5
- export type ResourceIdentity = Brand<'ResourceIdentity'>;
6
- export type WorkStepIdentity = Brand<'WorkStepIdentity'>;
7
- export type BranchStepIdentity = Brand<'BranchStepIdentity'>;
8
- export type ForStepIdentity = Brand<'ForStepIdentity'>;
9
- export type WhileStepIdentity = Brand<'WhileStepIdentity'>;
10
- export type ResourceFormatIdentity = Brand<'ResourceFormatIdentity'>;
11
- export type ResourceTypeIdentity = Brand<'ResourceTypeIdentity'>;
12
- export type ResourceRoleIdentity = Brand<'ResourceRoleIdentity'>;
13
- export type StatelessStrategyIdentity = Brand<'StatelessStrategyIdentity'>;
14
- export type StatefulStrategyIdentity = Brand<'StatefulStrategyIdentity'>;
15
- /** Generic unsafe brand helper when a bespoke factory is not available. */
16
- export declare function unsafeBrand<T extends string>(s: string): T;
17
- export declare const asResourceTypeIdentity: (s: string) => ResourceTypeIdentity;
18
- export declare const asResourceRoleIdentity: (s: string) => ResourceRoleIdentity;
19
- export declare const asExecutionIdentity: (s: string) => ExecutionIdentity;
20
- export declare const asResourceIdentity: (s: string) => ResourceIdentity;
21
- export declare const asWorkStepIdentity: (s: string) => WorkStepIdentity;
22
- export declare const asBranchStepIdentity: (s: string) => BranchStepIdentity;
23
- export declare const asForStepIdentity: (s: string) => ForStepIdentity;
24
- export declare const asResourceFormatIdentity: (s: string) => ResourceFormatIdentity;
25
- export declare const asWhileStepIdentity: (s: string) => WhileStepIdentity;
26
- export declare const asStatelessStrategyIdentity: (s: string) => StatelessStrategyIdentity;
27
- export declare const asStatefulStrategyIdentity: (s: string) => StatefulStrategyIdentity;
28
- export declare const asResourceTypeIdentities: (xs: string[]) => ResourceTypeIdentity[];
29
- export declare const asResourceRoleIdentities: (xs: string[]) => ResourceRoleIdentity[];
30
- export declare const asExecutionIdentities: (xs: string[]) => ExecutionIdentity[];
31
- export declare const asResourceIdentities: (xs: string[]) => ResourceIdentity[];
32
- export declare const asWorkStepIdentities: (xs: string[]) => WorkStepIdentity[];
33
- export declare const asBranchStepIdentities: (xs: string[]) => BranchStepIdentity[];
34
- export declare const asForStepIdentities: (xs: string[]) => ForStepIdentity[];
35
- export declare const asResourceFormatIdentities: (xs: string[]) => ResourceFormatIdentity[];
36
- export declare const asWhileStepIdentities: (xs: string[]) => WhileStepIdentity[];
37
- export declare const asStatelessStrategyIdentities: (xs: string[]) => StatelessStrategyIdentity[];
38
- export declare const asStatefulStrategyIdentities: (xs: string[]) => StatefulStrategyIdentity[];
39
- export {};
@@ -1,46 +0,0 @@
1
- // Optional runtime validation toggle. Off by default.
2
- // Enable by setting TP_BRAND_VALIDATE=1 (or NODE_ENV=development) when running.
3
- const shouldValidate = (typeof process !== "undefined" && !!process.env &&
4
- (process.env.TP_BRAND_VALIDATE === "1" || process.env.NODE_ENV === "development")) ||
5
- false;
6
- function makeFactory(name, pattern) {
7
- return (s) => {
8
- if (shouldValidate && pattern && !pattern.test(s)) {
9
- throw new TypeError(`Invalid ${name}: "${s}" does not match ${String(pattern)}`);
10
- }
11
- return s;
12
- };
13
- }
14
- /** Generic unsafe brand helper when a bespoke factory is not available. */
15
- export function unsafeBrand(s) {
16
- return s;
17
- }
18
- // Known patterns from schemas (when available)
19
- const RE_TYPE_IDENTITY = /^TYPE-.+$/;
20
- const RE_JOB_IDENTITY = /^JOB-.+$/;
21
- const RE_ROLE_IDENTITY = /^ROLE-.+$/;
22
- // Factories for each Identity-like type
23
- export const asResourceTypeIdentity = makeFactory("ResourceTypeIdentity", RE_TYPE_IDENTITY);
24
- export const asResourceRoleIdentity = makeFactory("ResourceRoleIdentity", RE_ROLE_IDENTITY);
25
- // IDs without strict regex patterns in the current schemas: keep unchecked casts.
26
- export const asExecutionIdentity = makeFactory("ExecutionIdentity");
27
- export const asResourceIdentity = makeFactory("ResourceIdentity");
28
- export const asWorkStepIdentity = makeFactory("WorkStepIdentity");
29
- export const asBranchStepIdentity = makeFactory("BranchStepIdentity");
30
- export const asForStepIdentity = makeFactory("ForStepIdentity");
31
- export const asResourceFormatIdentity = makeFactory("ResourceFormatIdentity");
32
- export const asWhileStepIdentity = makeFactory("WhileStepIdentity");
33
- export const asStatelessStrategyIdentity = makeFactory("StatelessStrategyIdentity");
34
- export const asStatefulStrategyIdentity = makeFactory("StatefulStrategyIdentity");
35
- // Batch helpers
36
- export const asResourceTypeIdentities = (xs) => xs.map(asResourceTypeIdentity);
37
- export const asResourceRoleIdentities = (xs) => xs.map(asResourceRoleIdentity);
38
- export const asExecutionIdentities = (xs) => xs.map(asExecutionIdentity);
39
- export const asResourceIdentities = (xs) => xs.map(asResourceIdentity);
40
- export const asWorkStepIdentities = (xs) => xs.map(asWorkStepIdentity);
41
- export const asBranchStepIdentities = (xs) => xs.map(asBranchStepIdentity);
42
- export const asForStepIdentities = (xs) => xs.map(asForStepIdentity);
43
- export const asResourceFormatIdentities = (xs) => xs.map(asResourceFormatIdentity);
44
- export const asWhileStepIdentities = (xs) => xs.map(asWhileStepIdentity);
45
- export const asStatelessStrategyIdentities = (xs) => xs.map(asStatelessStrategyIdentity);
46
- export const asStatefulStrategyIdentities = (xs) => xs.map(asStatefulStrategyIdentity);