@walkeros/transformer-validator 3.0.0 → 3.0.2

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/dev.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { JSONSchemaType } from 'ajv';
2
+ import { Flow } from '@walkeros/core';
2
3
 
3
4
  /**
4
5
  * Partial JSON Schema type - we auto-add type: 'object'.
5
- * Can include: required, properties, additionalProperties, etc.
6
6
  */
7
7
  type JsonSchema = Partial<JSONSchemaType<unknown>>;
8
8
 
@@ -12,6 +12,22 @@ type JsonSchema = Partial<JSONSchemaType<unknown>>;
12
12
  */
13
13
  declare const formatSchema: JsonSchema;
14
14
 
15
+ declare const validEvent: Flow.StepExample;
16
+ declare const invalidFormat: Flow.StepExample;
17
+ declare const contractValidationPass: Flow.StepExample;
18
+
19
+ declare const step_contractValidationPass: typeof contractValidationPass;
20
+ declare const step_invalidFormat: typeof invalidFormat;
21
+ declare const step_validEvent: typeof validEvent;
22
+ declare namespace step {
23
+ export { step_contractValidationPass as contractValidationPass, step_invalidFormat as invalidFormat, step_validEvent as validEvent };
24
+ }
25
+
26
+ declare const index_step: typeof step;
27
+ declare namespace index {
28
+ export { index_step as step };
29
+ }
30
+
15
31
  /**
16
32
  * Development exports for transformer-validator
17
33
  * Used by website documentation and examples
@@ -26,4 +42,4 @@ declare const schemas: {
26
42
  settings: JsonSchema;
27
43
  };
28
44
 
29
- export { formatSchema, schemas, settingsSchema };
45
+ export { index as examples, formatSchema, schemas, settingsSchema };
package/dist/dev.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { JSONSchemaType } from 'ajv';
2
+ import { Flow } from '@walkeros/core';
2
3
 
3
4
  /**
4
5
  * Partial JSON Schema type - we auto-add type: 'object'.
5
- * Can include: required, properties, additionalProperties, etc.
6
6
  */
7
7
  type JsonSchema = Partial<JSONSchemaType<unknown>>;
8
8
 
@@ -12,6 +12,22 @@ type JsonSchema = Partial<JSONSchemaType<unknown>>;
12
12
  */
13
13
  declare const formatSchema: JsonSchema;
14
14
 
15
+ declare const validEvent: Flow.StepExample;
16
+ declare const invalidFormat: Flow.StepExample;
17
+ declare const contractValidationPass: Flow.StepExample;
18
+
19
+ declare const step_contractValidationPass: typeof contractValidationPass;
20
+ declare const step_invalidFormat: typeof invalidFormat;
21
+ declare const step_validEvent: typeof validEvent;
22
+ declare namespace step {
23
+ export { step_contractValidationPass as contractValidationPass, step_invalidFormat as invalidFormat, step_validEvent as validEvent };
24
+ }
25
+
26
+ declare const index_step: typeof step;
27
+ declare namespace index {
28
+ export { index_step as step };
29
+ }
30
+
15
31
  /**
16
32
  * Development exports for transformer-validator
17
33
  * Used by website documentation and examples
@@ -26,4 +42,4 @@ declare const schemas: {
26
42
  settings: JsonSchema;
27
43
  };
28
44
 
29
- export { formatSchema, schemas, settingsSchema };
45
+ export { index as examples, formatSchema, schemas, settingsSchema };
package/dist/dev.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,n={};((e,r)=>{for(var o in r)t(e,o,{get:r[o],enumerable:!0})})(n,{formatSchema:()=>p,schemas:()=>c,settingsSchema:()=>s}),module.exports=(e=n,((e,n,p,s)=>{if(n&&"object"==typeof n||"function"==typeof n)for(let c of o(n))i.call(e,c)||c===p||t(e,c,{get:()=>n[c],enumerable:!(s=r(n,c))||s.enumerable});return e})(t({},"__esModule",{value:!0}),e));var p={type:"object",required:["name","entity","action","data","context","globals","custom","user","nested","consent","id","trigger","timestamp","timing","group","count","version","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},group:{type:"string"},count:{type:"number"},version:{type:"object",required:["source","tagging"],properties:{source:{type:"string"},tagging:{type:"number"}}},source:{type:"object",required:["type","id","previous_id"],properties:{type:{type:"string"},id:{type:"string"},previous_id:{type:"string"}}}}},s={type:"object",properties:{format:{type:"boolean",description:"Validate full WalkerOS.Event structure. Pre-compiled at init.",default:!0},contract:{type:"object",description:"Event-specific validation rules. Entity/action keyed, supports wildcards."}}},c={format:p,settings:s};//# sourceMappingURL=dev.js.map
1
+ "use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,p=(e,r)=>{for(var i in r)t(e,i,{get:r[i],enumerable:!0})},a={};p(a,{examples:()=>s,formatSchema:()=>n,schemas:()=>g,settingsSchema:()=>l}),module.exports=(e=a,((e,p,a,n)=>{if(p&&"object"==typeof p||"function"==typeof p)for(let s of i(p))o.call(e,s)||s===a||t(e,s,{get:()=>p[s],enumerable:!(n=r(p,s))||n.enumerable});return e})(t({},"__esModule",{value:!0}),e));var n={type:"object",required:["name","entity","action","data","context","globals","custom","user","nested","consent","id","trigger","timestamp","timing","group","count","version","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},group:{type:"string"},count:{type:"number"},version:{type:"object",required:["source","tagging"],properties:{source:{type:"string"},tagging:{type:"number"}}},source:{type:"object",required:["type","id","previous_id"],properties:{type:{type:"string"},id:{type:"string"},previous_id:{type:"string"}}}}},s={};p(s,{step:()=>c});var c={};p(c,{contractValidationPass:()=>y,invalidFormat:()=>m,validEvent:()=>u});var d=require("@walkeros/core"),u={in:(0,d.getEvent)("product view",{timestamp:1700000700,data:{id:"SKU-100",name:"Trail Runner Pro",price:129.99},source:{type:"web",id:"https://example.com",previous_id:""}}),out:{event:(0,d.getEvent)("product view",{timestamp:1700000700,data:{id:"SKU-100",name:"Trail Runner Pro",price:129.99},source:{type:"web",id:"https://example.com",previous_id:""}})}},m={in:{name:"invalid",data:{}},out:!1},y={description:"Contract validation passes when event data matches the entity.action JSON Schema",in:(0,d.getEvent)("order complete",{timestamp:1700000800,data:{id:"0rd3r1d",total:555,currency:"EUR"},source:{type:"web",id:"https://shop.example.com",previous_id:""}}),out:{event:(0,d.getEvent)("order complete",{timestamp:1700000800,data:{id:"0rd3r1d",total:555,currency:"EUR"},source:{type:"web",id:"https://shop.example.com",previous_id:""}})}},l={type:"object",properties:{format:{type:"boolean",description:"Validate full WalkerOS.Event structure. Pre-compiled at init.",default:!0},contract:{type:"object",description:"Event-specific validation rules. Entity/action keyed, supports wildcards."}}},g={format:n,settings:l};//# sourceMappingURL=dev.js.map
package/dist/dev.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dev.ts","../src/format-schema.ts"],"sourcesContent":["/**\n * Development exports for transformer-validator\n * Used by website documentation and examples\n */\nimport { formatSchema } from './format-schema';\nimport type { JsonSchema } from './types';\n\nexport { formatSchema };\n\n/**\n * JSON Schema describing ValidatorSettings for documentation.\n */\nexport const settingsSchema: JsonSchema = {\n type: 'object',\n properties: {\n format: {\n type: 'boolean',\n description:\n 'Validate full WalkerOS.Event structure. Pre-compiled at init.',\n default: true,\n },\n contract: {\n type: 'object',\n description:\n 'Event-specific validation rules. Entity/action keyed, supports wildcards.',\n },\n },\n};\n\n// Re-export for convenience\nexport const schemas: { format: JsonSchema; settings: JsonSchema } = {\n format: formatSchema,\n settings: settingsSchema,\n};\n","import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'context',\n 'globals',\n 'custom',\n 'user',\n 'nested',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'group',\n 'count',\n 'version',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n group: { type: 'string' },\n count: { type: 'number' },\n version: {\n type: 'object',\n required: ['source', 'tagging'],\n properties: {\n source: { type: 'string' },\n tagging: { type: 'number' },\n },\n },\n source: {\n type: 'object',\n required: ['type', 'id', 'previous_id'],\n properties: {\n type: { type: 'string' },\n id: { type: 'string' },\n previous_id: { type: 'string' },\n },\n },\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,QAAQ,EAAE,MAAM,QAAQ;AAAA,IACxB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,IAAI,EAAE,MAAM,SAAS;AAAA,IACrB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,WAAW,EAAE,MAAM,SAAS;AAAA,IAC5B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,OAAO,EAAE,MAAM,SAAS;AAAA,IACxB,OAAO,EAAE,MAAM,SAAS;AAAA,IACxB,SAAS;AAAA,MACP,MAAM;AAAA,MACN,UAAU,CAAC,UAAU,SAAS;AAAA,MAC9B,YAAY;AAAA,QACV,QAAQ,EAAE,MAAM,SAAS;AAAA,QACzB,SAAS,EAAE,MAAM,SAAS;AAAA,MAC5B;AAAA,IACF;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,UAAU,CAAC,QAAQ,MAAM,aAAa;AAAA,MACtC,YAAY;AAAA,QACV,MAAM,EAAE,MAAM,SAAS;AAAA,QACvB,IAAI,EAAE,MAAM,SAAS;AAAA,QACrB,aAAa,EAAE,MAAM,SAAS;AAAA,MAChC;AAAA,IACF;AAAA,EACF;AACF;;;ADnDO,IAAM,iBAA6B;AAAA,EACxC,MAAM;AAAA,EACN,YAAY;AAAA,IACV,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,aACE;AAAA,MACF,SAAS;AAAA,IACX;AAAA,IACA,UAAU;AAAA,MACR,MAAM;AAAA,MACN,aACE;AAAA,IACJ;AAAA,EACF;AACF;AAGO,IAAM,UAAwD;AAAA,EACnE,QAAQ;AAAA,EACR,UAAU;AACZ;","names":[]}
1
+ {"version":3,"sources":["../src/dev.ts","../src/format-schema.ts","../src/examples/index.ts","../src/examples/step.ts"],"sourcesContent":["/**\n * Development exports for transformer-validator\n * Used by website documentation and examples\n */\nimport { formatSchema } from './format-schema';\nimport type { JsonSchema } from './types';\n\nexport { formatSchema };\n\n/**\n * JSON Schema describing ValidatorSettings for documentation.\n */\nexport const settingsSchema: JsonSchema = {\n type: 'object',\n properties: {\n format: {\n type: 'boolean',\n description:\n 'Validate full WalkerOS.Event structure. Pre-compiled at init.',\n default: true,\n },\n contract: {\n type: 'object',\n description:\n 'Event-specific validation rules. Entity/action keyed, supports wildcards.',\n },\n },\n};\n\n// Re-export for convenience\nexport const schemas: { format: JsonSchema; settings: JsonSchema } = {\n format: formatSchema,\n settings: settingsSchema,\n};\n\nexport * as examples from './examples';\n","import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'context',\n 'globals',\n 'custom',\n 'user',\n 'nested',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'group',\n 'count',\n 'version',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n group: { type: 'string' },\n count: { type: 'number' },\n version: {\n type: 'object',\n required: ['source', 'tagging'],\n properties: {\n source: { type: 'string' },\n tagging: { type: 'number' },\n },\n },\n source: {\n type: 'object',\n required: ['type', 'id', 'previous_id'],\n properties: {\n type: { type: 'string' },\n id: { type: 'string' },\n previous_id: { type: 'string' },\n },\n },\n },\n};\n","export * as step from './step';\n","import type { Flow } from '@walkeros/core';\nimport { getEvent } from '@walkeros/core';\n\nexport const validEvent: Flow.StepExample = {\n in: getEvent('product view', {\n timestamp: 1700000700,\n data: { id: 'SKU-100', name: 'Trail Runner Pro', price: 129.99 },\n source: { type: 'web', id: 'https://example.com', previous_id: '' },\n }),\n out: {\n event: getEvent('product view', {\n timestamp: 1700000700,\n data: { id: 'SKU-100', name: 'Trail Runner Pro', price: 129.99 },\n source: { type: 'web', id: 'https://example.com', previous_id: '' },\n }),\n },\n};\n\nexport const invalidFormat: Flow.StepExample = {\n in: {\n name: 'invalid',\n data: {},\n },\n out: false,\n};\n\nexport const contractValidationPass: Flow.StepExample = {\n description:\n 'Contract validation passes when event data matches the entity.action JSON Schema',\n in: getEvent('order complete', {\n timestamp: 1700000800,\n data: { id: '0rd3r1d', total: 555, currency: 'EUR' },\n source: { type: 'web', id: 'https://shop.example.com', previous_id: '' },\n }),\n out: {\n event: getEvent('order complete', {\n timestamp: 1700000800,\n data: { id: '0rd3r1d', total: 555, currency: 'EUR' },\n source: { type: 'web', id: 'https://shop.example.com', previous_id: '' },\n }),\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,QAAQ,EAAE,MAAM,QAAQ;AAAA,IACxB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,IAAI,EAAE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A,EACT;AAAA,EACA,KAAK;AACP;AAEO,IAAM,yBAA2C;AAAA,EACtD,aACE;AAAA,EACF,QAAI,sBAAS,kBAAkB;AAAA,IAC7B,WAAW;AAAA,IACX,MAAM,EAAE,IAAI,WAAW,OAAO,KAAK,UAAU,MAAM;AAAA,IACnD,QAAQ,EAAE,MAAM,OAAO,IAAI,4BAA4B,aAAa,GAAG;AAAA,EACzE,CAAC;AAAA,EACD,KAAK;AAAA,IACH,WAAO,sBAAS,kBAAkB;AAAA,MAChC,WAAW;AAAA,MACX,MAAM,EAAE,IAAI,WAAW,OAAO,KAAK,UAAU,MAAM;AAAA,MACnD,QAAQ,EAAE,MAAM,OAAO,IAAI,4BAA4B,aAAa,GAAG;AAAA,IACzE,CAAC;AAAA,EACH;AACF;;;AH7BO,IAAM,iBAA6B;AAAA,EACxC,MAAM;AAAA,EACN,YAAY;AAAA,IACV,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,aACE;AAAA,MACF,SAAS;AAAA,IACX;AAAA,IACA,UAAU;AAAA,MACR,MAAM;AAAA,MACN,aACE;AAAA,IACJ;AAAA,EACF;AACF;AAGO,IAAM,UAAwD;AAAA,EACnE,QAAQ;AAAA,EACR,UAAU;AACZ;","names":[]}
package/dist/dev.mjs CHANGED
@@ -1 +1 @@
1
- var t={type:"object",required:["name","entity","action","data","context","globals","custom","user","nested","consent","id","trigger","timestamp","timing","group","count","version","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},group:{type:"string"},count:{type:"number"},version:{type:"object",required:["source","tagging"],properties:{source:{type:"string"},tagging:{type:"number"}}},source:{type:"object",required:["type","id","previous_id"],properties:{type:{type:"string"},id:{type:"string"},previous_id:{type:"string"}}}}},e={type:"object",properties:{format:{type:"boolean",description:"Validate full WalkerOS.Event structure. Pre-compiled at init.",default:!0},contract:{type:"object",description:"Event-specific validation rules. Entity/action keyed, supports wildcards."}}},r={format:t,settings:e};export{t as formatSchema,r as schemas,e as settingsSchema};//# sourceMappingURL=dev.mjs.map
1
+ var e=Object.defineProperty,t=(t,r)=>{for(var i in r)e(t,i,{get:r[i],enumerable:!0})},r={type:"object",required:["name","entity","action","data","context","globals","custom","user","nested","consent","id","trigger","timestamp","timing","group","count","version","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},group:{type:"string"},count:{type:"number"},version:{type:"object",required:["source","tagging"],properties:{source:{type:"string"},tagging:{type:"number"}}},source:{type:"object",required:["type","id","previous_id"],properties:{type:{type:"string"},id:{type:"string"},previous_id:{type:"string"}}}}},i={};t(i,{step:()=>o});var o={};t(o,{contractValidationPass:()=>s,invalidFormat:()=>n,validEvent:()=>a});import{getEvent as p}from"@walkeros/core";var a={in:p("product view",{timestamp:1700000700,data:{id:"SKU-100",name:"Trail Runner Pro",price:129.99},source:{type:"web",id:"https://example.com",previous_id:""}}),out:{event:p("product view",{timestamp:1700000700,data:{id:"SKU-100",name:"Trail Runner Pro",price:129.99},source:{type:"web",id:"https://example.com",previous_id:""}})}},n={in:{name:"invalid",data:{}},out:!1},s={description:"Contract validation passes when event data matches the entity.action JSON Schema",in:p("order complete",{timestamp:1700000800,data:{id:"0rd3r1d",total:555,currency:"EUR"},source:{type:"web",id:"https://shop.example.com",previous_id:""}}),out:{event:p("order complete",{timestamp:1700000800,data:{id:"0rd3r1d",total:555,currency:"EUR"},source:{type:"web",id:"https://shop.example.com",previous_id:""}})}},c={type:"object",properties:{format:{type:"boolean",description:"Validate full WalkerOS.Event structure. Pre-compiled at init.",default:!0},contract:{type:"object",description:"Event-specific validation rules. Entity/action keyed, supports wildcards."}}},d={format:r,settings:c};export{i as examples,r as formatSchema,d as schemas,c as settingsSchema};//# sourceMappingURL=dev.mjs.map
package/dist/dev.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/format-schema.ts","../src/dev.ts"],"sourcesContent":["import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'context',\n 'globals',\n 'custom',\n 'user',\n 'nested',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'group',\n 'count',\n 'version',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n group: { type: 'string' },\n count: { type: 'number' },\n version: {\n type: 'object',\n required: ['source', 'tagging'],\n properties: {\n source: { type: 'string' },\n tagging: { type: 'number' },\n },\n },\n source: {\n type: 'object',\n required: ['type', 'id', 'previous_id'],\n properties: {\n type: { type: 'string' },\n id: { type: 'string' },\n previous_id: { type: 'string' },\n },\n },\n },\n};\n","/**\n * Development exports for transformer-validator\n * Used by website documentation and examples\n */\nimport { formatSchema } from './format-schema';\nimport type { JsonSchema } from './types';\n\nexport { formatSchema };\n\n/**\n * JSON Schema describing ValidatorSettings for documentation.\n */\nexport const settingsSchema: JsonSchema = {\n type: 'object',\n properties: {\n format: {\n type: 'boolean',\n description:\n 'Validate full WalkerOS.Event structure. Pre-compiled at init.',\n default: true,\n },\n contract: {\n type: 'object',\n description:\n 'Event-specific validation rules. Entity/action keyed, supports wildcards.',\n },\n },\n};\n\n// Re-export for convenience\nexport const schemas: { format: JsonSchema; settings: JsonSchema } = {\n format: formatSchema,\n settings: settingsSchema,\n};\n"],"mappings":";AAMO,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,QAAQ,EAAE,MAAM,QAAQ;AAAA,IACxB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,IAAI,EAAE,MAAM,SAAS;AAAA,IACrB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,WAAW,EAAE,MAAM,SAAS;AAAA,IAC5B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,OAAO,EAAE,MAAM,SAAS;AAAA,IACxB,OAAO,EAAE,MAAM,SAAS;AAAA,IACxB,SAAS;AAAA,MACP,MAAM;AAAA,MACN,UAAU,CAAC,UAAU,SAAS;AAAA,MAC9B,YAAY;AAAA,QACV,QAAQ,EAAE,MAAM,SAAS;AAAA,QACzB,SAAS,EAAE,MAAM,SAAS;AAAA,MAC5B;AAAA,IACF;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,UAAU,CAAC,QAAQ,MAAM,aAAa;AAAA,MACtC,YAAY;AAAA,QACV,MAAM,EAAE,MAAM,SAAS;AAAA,QACvB,IAAI,EAAE,MAAM,SAAS;AAAA,QACrB,aAAa,EAAE,MAAM,SAAS;AAAA,MAChC;AAAA,IACF;AAAA,EACF;AACF;;;ACnDO,IAAM,iBAA6B;AAAA,EACxC,MAAM;AAAA,EACN,YAAY;AAAA,IACV,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,aACE;AAAA,MACF,SAAS;AAAA,IACX;AAAA,IACA,UAAU;AAAA,MACR,MAAM;AAAA,MACN,aACE;AAAA,IACJ;AAAA,EACF;AACF;AAGO,IAAM,UAAwD;AAAA,EACnE,QAAQ;AAAA,EACR,UAAU;AACZ;","names":[]}
1
+ {"version":3,"sources":["../src/format-schema.ts","../src/examples/index.ts","../src/examples/step.ts","../src/dev.ts"],"sourcesContent":["import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'context',\n 'globals',\n 'custom',\n 'user',\n 'nested',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'group',\n 'count',\n 'version',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n group: { type: 'string' },\n count: { type: 'number' },\n version: {\n type: 'object',\n required: ['source', 'tagging'],\n properties: {\n source: { type: 'string' },\n tagging: { type: 'number' },\n },\n },\n source: {\n type: 'object',\n required: ['type', 'id', 'previous_id'],\n properties: {\n type: { type: 'string' },\n id: { type: 'string' },\n previous_id: { type: 'string' },\n },\n },\n },\n};\n","export * as step from './step';\n","import type { Flow } from '@walkeros/core';\nimport { getEvent } from '@walkeros/core';\n\nexport const validEvent: Flow.StepExample = {\n in: getEvent('product view', {\n timestamp: 1700000700,\n data: { id: 'SKU-100', name: 'Trail Runner Pro', price: 129.99 },\n source: { type: 'web', id: 'https://example.com', previous_id: '' },\n }),\n out: {\n event: getEvent('product view', {\n timestamp: 1700000700,\n data: { id: 'SKU-100', name: 'Trail Runner Pro', price: 129.99 },\n source: { type: 'web', id: 'https://example.com', previous_id: '' },\n }),\n },\n};\n\nexport const invalidFormat: Flow.StepExample = {\n in: {\n name: 'invalid',\n data: {},\n },\n out: false,\n};\n\nexport const contractValidationPass: Flow.StepExample = {\n description:\n 'Contract validation passes when event data matches the entity.action JSON Schema',\n in: getEvent('order complete', {\n timestamp: 1700000800,\n data: { id: '0rd3r1d', total: 555, currency: 'EUR' },\n source: { type: 'web', id: 'https://shop.example.com', previous_id: '' },\n }),\n out: {\n event: getEvent('order complete', {\n timestamp: 1700000800,\n data: { id: '0rd3r1d', total: 555, currency: 'EUR' },\n source: { type: 'web', id: 'https://shop.example.com', previous_id: '' },\n }),\n },\n};\n","/**\n * Development exports for transformer-validator\n * Used by website documentation and examples\n */\nimport { formatSchema } from './format-schema';\nimport type { JsonSchema } from './types';\n\nexport { formatSchema };\n\n/**\n * JSON Schema describing ValidatorSettings for documentation.\n */\nexport const settingsSchema: JsonSchema = {\n type: 'object',\n properties: {\n format: {\n type: 'boolean',\n description:\n 'Validate full WalkerOS.Event structure. Pre-compiled at init.',\n default: true,\n },\n contract: {\n type: 'object',\n description:\n 'Event-specific validation rules. Entity/action keyed, supports wildcards.',\n },\n },\n};\n\n// Re-export for convenience\nexport const schemas: { format: JsonSchema; settings: JsonSchema } = {\n format: formatSchema,\n settings: settingsSchema,\n};\n\nexport * as examples from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MAAM;AAAA,EACN,YAAY;AAAA,IACV,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,aACE;AAAA,MACF,SAAS;AAAA,IACX;AAAA,IACA,UAAU;AAAA,MACR,MAAM;AAAA,MACN,aACE;AAAA,IACJ;AAAA,EACF;AACF;AAGO,IAAM,UAAwD;AAAA,EACnE,QAAQ;AAAA,EACR,UAAU;AACZ;","names":[]}
package/dist/index.d.mts CHANGED
@@ -1,59 +1,43 @@
1
- import { Mapping, WalkerOS, Transformer } from '@walkeros/core';
1
+ import { Transformer } from '@walkeros/core';
2
2
  import { JSONSchemaType } from 'ajv';
3
3
 
4
4
  /**
5
5
  * Partial JSON Schema type - we auto-add type: 'object'.
6
- * Can include: required, properties, additionalProperties, etc.
7
6
  */
8
7
  type JsonSchema = Partial<JSONSchemaType<unknown>>;
9
8
  /**
10
- * Contract rule for event-specific validation.
11
- * Extends the shape expected by getMappingEvent.
9
+ * Contract event rules entity → action → JSON Schema.
10
+ * The validator matches events by entity-action and validates
11
+ * against the corresponding schema.
12
12
  */
13
- interface ContractRule {
14
- /**
15
- * Condition function - first matching rule wins.
16
- * MUST be synchronous. getMappingEvent uses .find() which doesn't await.
17
- * For async checks, validate in the schema or use a separate transformer.
18
- */
19
- condition?: (event: WalkerOS.DeepPartialEvent) => boolean;
20
- /**
21
- * JSON Schema (partial) - we auto-add type: 'object'.
22
- * Can include: required, properties, additionalProperties, etc.
23
- */
24
- schema: JsonSchema;
25
- }
26
- /**
27
- * Contract extends Mapping.Rules for type compatibility with getMappingEvent.
28
- * This avoids `as any` casting and ensures strict typing.
29
- */
30
- type Contract = Mapping.Rules<ContractRule>;
13
+ type ContractEvents = Record<string, Record<string, JsonSchema>>;
31
14
  /**
32
15
  * Validator transformer settings.
33
16
  */
34
17
  interface ValidatorSettings {
35
18
  /**
36
19
  * Validate full WalkerOS.Event structure.
37
- * Pre-compiled at transformer init, runs on every event.
38
- * Validates all fields exist with correct types.
39
20
  * @default true
40
21
  */
41
22
  format?: boolean;
42
23
  /**
43
- * Event-specific validation rules.
44
- * Entity/action keyed, supports wildcards and conditions.
45
- * Schemas lazy-compiled on first match.
24
+ * Entity-action event validation schemas.
25
+ * Resolved from $contract.name.events.
26
+ * Supports wildcards via findEventSchema.
46
27
  */
47
- contract?: Contract;
28
+ events?: ContractEvents;
29
+ /** JSON Schema for event.globals — validates on every event. */
30
+ globals?: JsonSchema;
31
+ /** JSON Schema for event.context — validates on every event. */
32
+ context?: JsonSchema;
33
+ /** JSON Schema for event.custom — validates on every event. */
34
+ custom?: JsonSchema;
35
+ /** JSON Schema for event.user — validates on every event. */
36
+ user?: JsonSchema;
37
+ /** JSON Schema for event.consent — validates on every event. */
38
+ consent?: JsonSchema;
48
39
  }
49
40
 
50
- /**
51
- * Event validation transformer using AJV with JSON Schema.
52
- *
53
- * Two validation modes:
54
- * - format: Pre-compiled WalkerOS.Event structure validation (runs on every event)
55
- * - contract: Entity/action keyed business rules with lazy compilation
56
- */
57
41
  declare const transformerValidator: Transformer.Init<Transformer.Types<ValidatorSettings>>;
58
42
 
59
- export { type Contract, type ContractRule, type JsonSchema, type ValidatorSettings, transformerValidator as default, transformerValidator };
43
+ export { type ContractEvents, type JsonSchema, type ValidatorSettings, transformerValidator as default, transformerValidator };
package/dist/index.d.ts CHANGED
@@ -1,59 +1,43 @@
1
- import { Mapping, WalkerOS, Transformer } from '@walkeros/core';
1
+ import { Transformer } from '@walkeros/core';
2
2
  import { JSONSchemaType } from 'ajv';
3
3
 
4
4
  /**
5
5
  * Partial JSON Schema type - we auto-add type: 'object'.
6
- * Can include: required, properties, additionalProperties, etc.
7
6
  */
8
7
  type JsonSchema = Partial<JSONSchemaType<unknown>>;
9
8
  /**
10
- * Contract rule for event-specific validation.
11
- * Extends the shape expected by getMappingEvent.
9
+ * Contract event rules entity → action → JSON Schema.
10
+ * The validator matches events by entity-action and validates
11
+ * against the corresponding schema.
12
12
  */
13
- interface ContractRule {
14
- /**
15
- * Condition function - first matching rule wins.
16
- * MUST be synchronous. getMappingEvent uses .find() which doesn't await.
17
- * For async checks, validate in the schema or use a separate transformer.
18
- */
19
- condition?: (event: WalkerOS.DeepPartialEvent) => boolean;
20
- /**
21
- * JSON Schema (partial) - we auto-add type: 'object'.
22
- * Can include: required, properties, additionalProperties, etc.
23
- */
24
- schema: JsonSchema;
25
- }
26
- /**
27
- * Contract extends Mapping.Rules for type compatibility with getMappingEvent.
28
- * This avoids `as any` casting and ensures strict typing.
29
- */
30
- type Contract = Mapping.Rules<ContractRule>;
13
+ type ContractEvents = Record<string, Record<string, JsonSchema>>;
31
14
  /**
32
15
  * Validator transformer settings.
33
16
  */
34
17
  interface ValidatorSettings {
35
18
  /**
36
19
  * Validate full WalkerOS.Event structure.
37
- * Pre-compiled at transformer init, runs on every event.
38
- * Validates all fields exist with correct types.
39
20
  * @default true
40
21
  */
41
22
  format?: boolean;
42
23
  /**
43
- * Event-specific validation rules.
44
- * Entity/action keyed, supports wildcards and conditions.
45
- * Schemas lazy-compiled on first match.
24
+ * Entity-action event validation schemas.
25
+ * Resolved from $contract.name.events.
26
+ * Supports wildcards via findEventSchema.
46
27
  */
47
- contract?: Contract;
28
+ events?: ContractEvents;
29
+ /** JSON Schema for event.globals — validates on every event. */
30
+ globals?: JsonSchema;
31
+ /** JSON Schema for event.context — validates on every event. */
32
+ context?: JsonSchema;
33
+ /** JSON Schema for event.custom — validates on every event. */
34
+ custom?: JsonSchema;
35
+ /** JSON Schema for event.user — validates on every event. */
36
+ user?: JsonSchema;
37
+ /** JSON Schema for event.consent — validates on every event. */
38
+ consent?: JsonSchema;
48
39
  }
49
40
 
50
- /**
51
- * Event validation transformer using AJV with JSON Schema.
52
- *
53
- * Two validation modes:
54
- * - format: Pre-compiled WalkerOS.Event structure validation (runs on every event)
55
- * - contract: Entity/action keyed business rules with lazy compilation
56
- */
57
41
  declare const transformerValidator: Transformer.Init<Transformer.Types<ValidatorSettings>>;
58
42
 
59
- export { type Contract, type ContractRule, type JsonSchema, type ValidatorSettings, transformerValidator as default, transformerValidator };
43
+ export { type ContractEvents, type JsonSchema, type ValidatorSettings, transformerValidator as default, transformerValidator };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t=Object.create,r=Object.defineProperty,o=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,i=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,a=(e,t,i,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let p of n(t))s.call(e,p)||p===i||r(e,p,{get:()=>t[p],enumerable:!(a=o(t,p))||a.enumerable});return e},p={};((e,t)=>{for(var o in t)r(e,o,{get:t[o],enumerable:!0})})(p,{default:()=>y,transformerValidator:()=>y}),module.exports=(e=p,a(r({},"__esModule",{value:!0}),e));var c=((e,o,n)=>(n=null!=e?t(i(e)):{},a(!o&&e&&e.__esModule?n:r(n,"default",{value:e,enumerable:!0}),e)))(require("ajv")),u=require("@walkeros/core"),g={type:"object",required:["name","entity","action","data","context","globals","custom","user","nested","consent","id","trigger","timestamp","timing","group","count","version","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},group:{type:"string"},count:{type:"number"},version:{type:"object",required:["source","tagging"],properties:{source:{type:"string"},tagging:{type:"number"}}},source:{type:"object",required:["type","id","previous_id"],properties:{type:{type:"string"},id:{type:"string"},previous_id:{type:"string"}}}}},y=e=>{const{config:t}=e,r=t.settings||{},{format:o=!0,contract:n}=r,i=new c.default({allErrors:!0,strict:!1}),s=o?i.compile(g):null,a=new WeakMap;return{type:"validator",config:t,async push(e,t){const{logger:r}=t;if(s&&!s(e))return r.error("Event format invalid",{errors:i.errorsText(s.errors)}),!1;if(n){const{eventMapping:t,mappingKey:o}=await(0,u.getMappingEvent)(e,n),s=t;if(null==s?void 0:s.schema){const t=function(e){if(!a.has(e)){const t={type:"object",...e};a.set(e,i.compile(t))}return a.get(e)}(s.schema);if(!t(e))return r.error("Contract validation failed",{rule:o,errors:i.errorsText(t.errors)}),!1;r.debug("Contract validation passed",{rule:o})}}return e}}};//# sourceMappingURL=index.js.map
1
+ "use strict";var e,t=Object.create,r=Object.defineProperty,o=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,i=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,a=(e,t,i,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let c of n(t))s.call(e,c)||c===i||r(e,c,{get:()=>t[c],enumerable:!(a=o(t,c))||a.enumerable});return e},c={};((e,t)=>{for(var o in t)r(e,o,{get:t[o],enumerable:!0})})(c,{default:()=>l,transformerValidator:()=>l}),module.exports=(e=c,a(r({},"__esModule",{value:!0}),e));var u=((e,o,n)=>(n=null!=e?t(i(e)):{},a(!o&&e&&e.__esModule?n:r(n,"default",{value:e,enumerable:!0}),e)))(require("ajv")),p={type:"object",required:["name","entity","action","data","context","globals","custom","user","nested","consent","id","trigger","timestamp","timing","group","count","version","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},group:{type:"string"},count:{type:"number"},version:{type:"object",required:["source","tagging"],properties:{source:{type:"string"},tagging:{type:"number"}}},source:{type:"object",required:["type","id","previous_id"],properties:{type:{type:"string"},id:{type:"string"},previous_id:{type:"string"}}}}},l=e=>{const{config:t}=e,r=t.settings||{},{format:o=!0,events:n,globals:i,context:s,custom:a,user:c,consent:l}=r,y=new u.default({allErrors:!0,strict:!1}),g=o?y.compile(p):null,d=[],m={globals:i,context:s,custom:a,user:c,consent:l};for(const[e,t]of Object.entries(m))t&&d.push({name:e,field:e,validate:y.compile({type:"object",...t})});const f=new Map;return{type:"validator",config:t,async push(e,t){const{logger:r}=t;if(g&&!g(e))return r.error("Event format invalid",{errors:y.errorsText(g.errors)}),!1;for(const{name:t,field:o,validate:n}of d){if(!n(e[o]))return r.error(`${t} validation failed`,{errors:y.errorsText(n.errors)}),!1}if(n&&e.entity&&e.action){const t=function(e,t){var r,o,i,s;if(n)return(null==(r=n[e])?void 0:r[t])?{schema:n[e][t],key:`${e} ${t}`}:(null==(o=n[e])?void 0:o["*"])?{schema:n[e]["*"],key:`${e} *`}:(null==(i=n["*"])?void 0:i[t])?{schema:n["*"][t],key:`* ${t}`}:(null==(s=n["*"])?void 0:s["*"])?{schema:n["*"]["*"],key:"* *"}:void 0}(e.entity,e.action);if(t){const o=function(e,t,r){const o=`${e}.${t}`;return f.has(o)||f.set(o,y.compile({type:"object",...r})),f.get(o)}(e.entity,e.action,t.schema);if(!o(e))return r.error("Contract validation failed",{rule:t.key,errors:y.errorsText(o.errors)}),!1;r.debug("Contract validation passed",{rule:t.key})}}return{event:e}}}};//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/transformer.ts","../src/format-schema.ts"],"sourcesContent":["export { transformerValidator } from './transformer';\nexport type {\n ValidatorSettings,\n Contract,\n ContractRule,\n JsonSchema,\n} from './types';\n\nexport { transformerValidator as default } from './transformer';\n","import Ajv, { ValidateFunction } from 'ajv';\nimport { getMappingEvent } from '@walkeros/core';\nimport type { Mapping, Transformer } from '@walkeros/core';\nimport { formatSchema } from './format-schema';\nimport type { ValidatorSettings, ContractRule, JsonSchema } from './types';\n\n/**\n * Event validation transformer using AJV with JSON Schema.\n *\n * Two validation modes:\n * - format: Pre-compiled WalkerOS.Event structure validation (runs on every event)\n * - contract: Entity/action keyed business rules with lazy compilation\n */\nexport const transformerValidator: Transformer.Init<\n Transformer.Types<ValidatorSettings>\n> = (context) => {\n const { config } = context;\n const settings = config.settings || {};\n const { format = true, contract } = settings;\n\n const ajv = new Ajv({ allErrors: true, strict: false });\n\n // Pre-compile format validator (runs on every event)\n const formatValidator = format ? ajv.compile(formatSchema) : null;\n\n // Lazy-compiled contract validators - keyed by schema reference\n // Using WeakMap to cache by schema object, handling array rules with conditions\n const contractValidators = new WeakMap<JsonSchema, ValidateFunction>();\n\n function getContractValidator(schema: JsonSchema) {\n if (!contractValidators.has(schema)) {\n // Auto-wrap with type: 'object'\n const fullSchema = { type: 'object', ...schema };\n contractValidators.set(schema, ajv.compile(fullSchema));\n }\n return contractValidators.get(schema)!;\n }\n\n return {\n type: 'validator',\n config,\n\n async push(event, context) {\n const { logger } = context;\n\n // 1. Format validation (pre-compiled, fast)\n if (formatValidator && !formatValidator(event)) {\n logger.error('Event format invalid', {\n errors: ajv.errorsText(formatValidator.errors),\n });\n return false;\n }\n\n // 2. Contract validation (lazy compiled)\n if (contract) {\n // Contract is typed as Mapping.Rules<ContractRule> - cast needed for getMappingEvent\n const { eventMapping: rule, mappingKey } = await getMappingEvent(\n event,\n contract as Mapping.Rules,\n );\n\n // Type assertion: we know our rules have schema\n const contractRule = rule as ContractRule | undefined;\n\n if (contractRule?.schema) {\n const validator = getContractValidator(contractRule.schema);\n\n if (!validator(event)) {\n logger.error('Contract validation failed', {\n rule: mappingKey,\n errors: ajv.errorsText(validator.errors),\n });\n return false;\n }\n\n logger.debug('Contract validation passed', { rule: mappingKey });\n }\n }\n\n return event;\n },\n };\n};\n","import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'context',\n 'globals',\n 'custom',\n 'user',\n 'nested',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'group',\n 'count',\n 'version',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n group: { type: 'string' },\n count: { type: 'number' },\n version: {\n type: 'object',\n required: ['source', 'tagging'],\n properties: {\n source: { type: 'string' },\n tagging: { type: 'number' },\n },\n },\n source: {\n type: 'object',\n required: ['type', 'id', 'previous_id'],\n properties: {\n type: { type: 'string' },\n id: { type: 'string' },\n previous_id: { type: 'string' },\n },\n },\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAsC;AACtC,kBAAgC;;;ACKzB,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,QAAQ,EAAE,MAAM,QAAQ;AAAA,IACxB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,IAAI,EAAE,MAAM,S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B,YAAM,EAAE,OAAO,IAAIA;AAGnB,UAAI,mBAAmB,CAAC,gBAAgB,KAAK,GAAG;AAC9C,eAAO,MAAM,wBAAwB;AAAA,UACnC,QAAQ,IAAI,WAAW,gBAAgB,MAAM;AAAA,QAC/C,CAAC;AACD,eAAO;AAAA,MACT;AAGA,UAAI,UAAU;AAEZ,cAAM,EAAE,cAAc,MAAM,WAAW,IAAI,UAAM;AAAA,UAC/C;AAAA,UACA;AAAA,QACF;AAGA,cAAM,eAAe;AAErB,YAAI,6CAAc,QAAQ;AACxB,gBAAM,YAAY,qBAAqB,aAAa,MAAM;AAE1D,cAAI,CAAC,UAAU,KAAK,GAAG;AACrB,mBAAO,MAAM,8BAA8B;AAAA,cACzC,MAAM;AAAA,cACN,QAAQ,IAAI,WAAW,UAAU,MAAM;AAAA,YACzC,CAAC;AACD,mBAAO;AAAA,UACT;AAEA,iBAAO,MAAM,8BAA8B,EAAE,MAAM,WAAW,CAAC;AAAA,QACjE;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["Ajv","context"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/transformer.ts","../src/format-schema.ts"],"sourcesContent":["export { transformerValidator } from './transformer';\nexport type { ValidatorSettings, ContractEvents, JsonSchema } from './types';\n\nexport { transformerValidator as default } from './transformer';\n","import Ajv, { ValidateFunction } from 'ajv';\nimport type { Transformer } from '@walkeros/core';\nimport { formatSchema } from './format-schema';\nimport type { ValidatorSettings, JsonSchema } from './types';\n\nexport const transformerValidator: Transformer.Init<\n Transformer.Types<ValidatorSettings>\n> = (context) => {\n const { config } = context;\n const settings = config.settings || {};\n const {\n format = true,\n events,\n globals,\n context: ctx,\n custom,\n user,\n consent,\n } = settings;\n\n const ajv = new Ajv({ allErrors: true, strict: false });\n\n // Pre-compile format validator\n const formatValidator = format ? ajv.compile(formatSchema) : null;\n\n // Pre-compile section validators (run on every event)\n const sectionValidators: Array<{\n name: string;\n field: string;\n validate: ValidateFunction;\n }> = [];\n\n const sectionSchemas = { globals, context: ctx, custom, user, consent };\n for (const [name, schema] of Object.entries(sectionSchemas)) {\n if (schema) {\n sectionValidators.push({\n name,\n field: name,\n validate: ajv.compile({ type: 'object', ...schema }),\n });\n }\n }\n\n // Lazy-compiled event validators\n const eventValidators = new Map<string, ValidateFunction>();\n\n function getEventValidator(\n entity: string,\n action: string,\n schema: JsonSchema,\n ) {\n const key = `${entity}.${action}`;\n if (!eventValidators.has(key)) {\n eventValidators.set(key, ajv.compile({ type: 'object', ...schema }));\n }\n return eventValidators.get(key)!;\n }\n\n /**\n * Find matching event schema using wildcard fallback.\n * Checks: entity.action → entity.* → *.action → *.*\n */\n function findEventSchema(\n entity: string,\n action: string,\n ): { schema: JsonSchema; key: string } | undefined {\n if (!events) return undefined;\n\n // Direct match\n if (events[entity]?.[action]) {\n return { schema: events[entity][action], key: `${entity} ${action}` };\n }\n // Entity wildcard\n if (events[entity]?.['*']) {\n return { schema: events[entity]['*'], key: `${entity} *` };\n }\n // Action wildcard\n if (events['*']?.[action]) {\n return { schema: events['*'][action], key: `* ${action}` };\n }\n // Global wildcard\n if (events['*']?.['*']) {\n return { schema: events['*']['*'], key: '* *' };\n }\n return undefined;\n }\n\n return {\n type: 'validator',\n config,\n\n async push(event, context) {\n const { logger } = context;\n\n // 1. Format validation (pre-compiled, fast)\n if (formatValidator && !formatValidator(event)) {\n logger.error('Event format invalid', {\n errors: ajv.errorsText(formatValidator.errors),\n });\n return false;\n }\n\n // 2. Section validation (pre-compiled, runs on every event)\n for (const { name, field, validate } of sectionValidators) {\n const value = (event as Record<string, unknown>)[field];\n if (!validate(value)) {\n logger.error(`${name} validation failed`, {\n errors: ajv.errorsText(validate.errors),\n });\n return false;\n }\n }\n\n // 3. Event validation (lazy compiled)\n if (events && event.entity && event.action) {\n const match = findEventSchema(event.entity, event.action);\n\n if (match) {\n const validator = getEventValidator(\n event.entity,\n event.action,\n match.schema,\n );\n\n if (!validator(event)) {\n logger.error('Contract validation failed', {\n rule: match.key,\n errors: ajv.errorsText(validator.errors),\n });\n return false;\n }\n\n logger.debug('Contract validation passed', { rule: match.key });\n }\n }\n\n return { event };\n },\n };\n};\n","import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'context',\n 'globals',\n 'custom',\n 'user',\n 'nested',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'group',\n 'count',\n 'version',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n group: { type: 'string' },\n count: { type: 'number' },\n version: {\n type: 'object',\n required: ['source', 'tagging'],\n properties: {\n source: { type: 'string' },\n tagging: { type: 'number' },\n },\n },\n source: {\n type: 'object',\n required: ['type', 'id', 'previous_id'],\n properties: {\n type: { type: 'string' },\n id: { type: 'string' },\n previous_id: { type: 'string' },\n },\n },\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAsC;;;ACM/B,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EAC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js CHANGED
@@ -1 +1 @@
1
- import e from"ajv";import{getMappingEvent as t}from"@walkeros/core";var r={type:"object",required:["name","entity","action","data","context","globals","custom","user","nested","consent","id","trigger","timestamp","timing","group","count","version","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},group:{type:"string"},count:{type:"number"},version:{type:"object",required:["source","tagging"],properties:{source:{type:"string"},tagging:{type:"number"}}},source:{type:"object",required:["type","id","previous_id"],properties:{type:{type:"string"},id:{type:"string"},previous_id:{type:"string"}}}}},o=o=>{const{config:n}=o,i=n.settings||{},{format:s=!0,contract:p}=i,a=new e({allErrors:!0,strict:!1}),c=s?a.compile(r):null,g=new WeakMap;return{type:"validator",config:n,async push(e,r){const{logger:o}=r;if(c&&!c(e))return o.error("Event format invalid",{errors:a.errorsText(c.errors)}),!1;if(p){const{eventMapping:r,mappingKey:n}=await t(e,p),i=r;if(null==i?void 0:i.schema){const t=function(e){if(!g.has(e)){const t={type:"object",...e};g.set(e,a.compile(t))}return g.get(e)}(i.schema);if(!t(e))return o.error("Contract validation failed",{rule:n,errors:a.errorsText(t.errors)}),!1;o.debug("Contract validation passed",{rule:n})}}return e}}};export{o as default,o as transformerValidator};//# sourceMappingURL=index.mjs.map
1
+ import e from"ajv";var t={type:"object",required:["name","entity","action","data","context","globals","custom","user","nested","consent","id","trigger","timestamp","timing","group","count","version","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},group:{type:"string"},count:{type:"number"},version:{type:"object",required:["source","tagging"],properties:{source:{type:"string"},tagging:{type:"number"}}},source:{type:"object",required:["type","id","previous_id"],properties:{type:{type:"string"},id:{type:"string"},previous_id:{type:"string"}}}}},r=r=>{const{config:o}=r,n=o.settings||{},{format:i=!0,events:s,globals:c,context:a,custom:p,user:u,consent:y}=n,l=new e({allErrors:!0,strict:!1}),g=i?l.compile(t):null,d=[],m={globals:c,context:a,custom:p,user:u,consent:y};for(const[e,t]of Object.entries(m))t&&d.push({name:e,field:e,validate:l.compile({type:"object",...t})});const f=new Map;return{type:"validator",config:o,async push(e,t){const{logger:r}=t;if(g&&!g(e))return r.error("Event format invalid",{errors:l.errorsText(g.errors)}),!1;for(const{name:t,field:o,validate:n}of d){if(!n(e[o]))return r.error(`${t} validation failed`,{errors:l.errorsText(n.errors)}),!1}if(s&&e.entity&&e.action){const t=function(e,t){var r,o,n,i;if(s)return(null==(r=s[e])?void 0:r[t])?{schema:s[e][t],key:`${e} ${t}`}:(null==(o=s[e])?void 0:o["*"])?{schema:s[e]["*"],key:`${e} *`}:(null==(n=s["*"])?void 0:n[t])?{schema:s["*"][t],key:`* ${t}`}:(null==(i=s["*"])?void 0:i["*"])?{schema:s["*"]["*"],key:"* *"}:void 0}(e.entity,e.action);if(t){const o=function(e,t,r){const o=`${e}.${t}`;return f.has(o)||f.set(o,l.compile({type:"object",...r})),f.get(o)}(e.entity,e.action,t.schema);if(!o(e))return r.error("Contract validation failed",{rule:t.key,errors:l.errorsText(o.errors)}),!1;r.debug("Contract validation passed",{rule:t.key})}}return{event:e}}}};export{r as default,r as transformerValidator};//# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/transformer.ts","../src/format-schema.ts"],"sourcesContent":["import Ajv, { ValidateFunction } from 'ajv';\nimport { getMappingEvent } from '@walkeros/core';\nimport type { Mapping, Transformer } from '@walkeros/core';\nimport { formatSchema } from './format-schema';\nimport type { ValidatorSettings, ContractRule, JsonSchema } from './types';\n\n/**\n * Event validation transformer using AJV with JSON Schema.\n *\n * Two validation modes:\n * - format: Pre-compiled WalkerOS.Event structure validation (runs on every event)\n * - contract: Entity/action keyed business rules with lazy compilation\n */\nexport const transformerValidator: Transformer.Init<\n Transformer.Types<ValidatorSettings>\n> = (context) => {\n const { config } = context;\n const settings = config.settings || {};\n const { format = true, contract } = settings;\n\n const ajv = new Ajv({ allErrors: true, strict: false });\n\n // Pre-compile format validator (runs on every event)\n const formatValidator = format ? ajv.compile(formatSchema) : null;\n\n // Lazy-compiled contract validators - keyed by schema reference\n // Using WeakMap to cache by schema object, handling array rules with conditions\n const contractValidators = new WeakMap<JsonSchema, ValidateFunction>();\n\n function getContractValidator(schema: JsonSchema) {\n if (!contractValidators.has(schema)) {\n // Auto-wrap with type: 'object'\n const fullSchema = { type: 'object', ...schema };\n contractValidators.set(schema, ajv.compile(fullSchema));\n }\n return contractValidators.get(schema)!;\n }\n\n return {\n type: 'validator',\n config,\n\n async push(event, context) {\n const { logger } = context;\n\n // 1. Format validation (pre-compiled, fast)\n if (formatValidator && !formatValidator(event)) {\n logger.error('Event format invalid', {\n errors: ajv.errorsText(formatValidator.errors),\n });\n return false;\n }\n\n // 2. Contract validation (lazy compiled)\n if (contract) {\n // Contract is typed as Mapping.Rules<ContractRule> - cast needed for getMappingEvent\n const { eventMapping: rule, mappingKey } = await getMappingEvent(\n event,\n contract as Mapping.Rules,\n );\n\n // Type assertion: we know our rules have schema\n const contractRule = rule as ContractRule | undefined;\n\n if (contractRule?.schema) {\n const validator = getContractValidator(contractRule.schema);\n\n if (!validator(event)) {\n logger.error('Contract validation failed', {\n rule: mappingKey,\n errors: ajv.errorsText(validator.errors),\n });\n return false;\n }\n\n logger.debug('Contract validation passed', { rule: mappingKey });\n }\n }\n\n return event;\n },\n };\n};\n","import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'context',\n 'globals',\n 'custom',\n 'user',\n 'nested',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'group',\n 'count',\n 'version',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n group: { type: 'string' },\n count: { type: 'number' },\n version: {\n type: 'object',\n required: ['source', 'tagging'],\n properties: {\n source: { type: 'string' },\n tagging: { type: 'number' },\n },\n },\n source: {\n type: 'object',\n required: ['type', 'id', 'previous_id'],\n properties: {\n type: { type: 'string' },\n id: { type: 'string' },\n previous_id: { type: 'string' },\n },\n },\n },\n};\n"],"mappings":";AAAA,OAAO,SAA+B;AACtC,SAAS,uBAAuB;;;ACKzB,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,M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AAmB,IAAI,MAAM;AAAA,EACtC;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IAEA,MAAM,KAAK,OAAOA,UAAS;AACzB,YAAM,EAAE,OAAO,IAAIA;AAGnB,UAAI,mBAAmB,CAAC,gBAAgB,KAAK,GAAG;AAC9C,eAAO,MAAM,wBAAwB;AAAA,UACnC,QAAQ,IAAI,WAAW,gBAAgB,MAAM;AAAA,QAC/C,CAAC;AACD,eAAO;AAAA,MACT;AAGA,UAAI,UAAU;AAEZ,cAAM,EAAE,cAAc,MAAM,WAAW,IAAI,MAAM;AAAA,UAC/C;AAAA,UACA;AAAA,QACF;AAGA,cAAM,eAAe;AAErB,YAAI,6CAAc,QAAQ;AACxB,gBAAM,YAAY,qBAAqB,aAAa,MAAM;AAE1D,cAAI,CAAC,UAAU,KAAK,GAAG;AACrB,mBAAO,MAAM,8BAA8B;AAAA,cACzC,MAAM;AAAA,cACN,QAAQ,IAAI,WAAW,UAAU,MAAM;AAAA,YACzC,CAAC;AACD,mBAAO;AAAA,UACT;AAEA,iBAAO,MAAM,8BAA8B,EAAE,MAAM,WAAW,CAAC;AAAA,QACjE;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["context"]}
1
+ {"version":3,"sources":["../src/transformer.ts","../src/format-schema.ts"],"sourcesContent":["import Ajv, { ValidateFunction } from 'ajv';\nimport type { Transformer } from '@walkeros/core';\nimport { formatSchema } from './format-schema';\nimport type { ValidatorSettings, JsonSchema } from './types';\n\nexport const transformerValidator: Transformer.Init<\n Transformer.Types<ValidatorSettings>\n> = (context) => {\n const { config } = context;\n const settings = config.settings || {};\n const {\n format = true,\n events,\n globals,\n context: ctx,\n custom,\n user,\n consent,\n } = settings;\n\n const ajv = new Ajv({ allErrors: true, strict: false });\n\n // Pre-compile format validator\n const formatValidator = format ? ajv.compile(formatSchema) : null;\n\n // Pre-compile section validators (run on every event)\n const sectionValidators: Array<{\n name: string;\n field: string;\n validate: ValidateFunction;\n }> = [];\n\n const sectionSchemas = { globals, context: ctx, custom, user, consent };\n for (const [name, schema] of Object.entries(sectionSchemas)) {\n if (schema) {\n sectionValidators.push({\n name,\n field: name,\n validate: ajv.compile({ type: 'object', ...schema }),\n });\n }\n }\n\n // Lazy-compiled event validators\n const eventValidators = new Map<string, ValidateFunction>();\n\n function getEventValidator(\n entity: string,\n action: string,\n schema: JsonSchema,\n ) {\n const key = `${entity}.${action}`;\n if (!eventValidators.has(key)) {\n eventValidators.set(key, ajv.compile({ type: 'object', ...schema }));\n }\n return eventValidators.get(key)!;\n }\n\n /**\n * Find matching event schema using wildcard fallback.\n * Checks: entity.action → entity.* → *.action → *.*\n */\n function findEventSchema(\n entity: string,\n action: string,\n ): { schema: JsonSchema; key: string } | undefined {\n if (!events) return undefined;\n\n // Direct match\n if (events[entity]?.[action]) {\n return { schema: events[entity][action], key: `${entity} ${action}` };\n }\n // Entity wildcard\n if (events[entity]?.['*']) {\n return { schema: events[entity]['*'], key: `${entity} *` };\n }\n // Action wildcard\n if (events['*']?.[action]) {\n return { schema: events['*'][action], key: `* ${action}` };\n }\n // Global wildcard\n if (events['*']?.['*']) {\n return { schema: events['*']['*'], key: '* *' };\n }\n return undefined;\n }\n\n return {\n type: 'validator',\n config,\n\n async push(event, context) {\n const { logger } = context;\n\n // 1. Format validation (pre-compiled, fast)\n if (formatValidator && !formatValidator(event)) {\n logger.error('Event format invalid', {\n errors: ajv.errorsText(formatValidator.errors),\n });\n return false;\n }\n\n // 2. Section validation (pre-compiled, runs on every event)\n for (const { name, field, validate } of sectionValidators) {\n const value = (event as Record<string, unknown>)[field];\n if (!validate(value)) {\n logger.error(`${name} validation failed`, {\n errors: ajv.errorsText(validate.errors),\n });\n return false;\n }\n }\n\n // 3. Event validation (lazy compiled)\n if (events && event.entity && event.action) {\n const match = findEventSchema(event.entity, event.action);\n\n if (match) {\n const validator = getEventValidator(\n event.entity,\n event.action,\n match.schema,\n );\n\n if (!validator(event)) {\n logger.error('Contract validation failed', {\n rule: match.key,\n errors: ajv.errorsText(validator.errors),\n });\n return false;\n }\n\n logger.debug('Contract validation passed', { rule: match.key });\n }\n }\n\n return { event };\n },\n };\n};\n","import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'context',\n 'globals',\n 'custom',\n 'user',\n 'nested',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'group',\n 'count',\n 'version',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n group: { type: 'string' },\n count: { type: 'number' },\n version: {\n type: 'object',\n required: ['source', 'tagging'],\n properties: {\n source: { type: 'string' },\n tagging: { type: 'number' },\n },\n },\n source: {\n type: 'object',\n required: ['type', 'id', 'previous_id'],\n properties: {\n type: { type: 'string' },\n id: { type: 'string' },\n previous_id: { type: 'string' },\n },\n },\n },\n};\n"],"mappings":";AAAA,OAAO,SAA+B;;;ACM/B,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;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5
+ "type": "transformer",
6
+ "docs": "https://www.walkeros.io/docs/transformers/validator",
7
+ "source": "https://github.com/elbwalker/walkerOS/tree/main/packages/transformers/validator/src"
8
+ },
9
+ "schemas": {
10
+ "format": {
11
+ "type": "object",
12
+ "required": [
13
+ "name",
14
+ "entity",
15
+ "action",
16
+ "data",
17
+ "context",
18
+ "globals",
19
+ "custom",
20
+ "user",
21
+ "nested",
22
+ "consent",
23
+ "id",
24
+ "trigger",
25
+ "timestamp",
26
+ "timing",
27
+ "group",
28
+ "count",
29
+ "version",
30
+ "source"
31
+ ],
32
+ "properties": {
33
+ "name": {
34
+ "type": "string",
35
+ "pattern": "^\\S+ \\S+$"
36
+ },
37
+ "entity": {
38
+ "type": "string"
39
+ },
40
+ "action": {
41
+ "type": "string"
42
+ },
43
+ "data": {
44
+ "type": "object"
45
+ },
46
+ "context": {
47
+ "type": "object"
48
+ },
49
+ "globals": {
50
+ "type": "object"
51
+ },
52
+ "custom": {
53
+ "type": "object"
54
+ },
55
+ "user": {
56
+ "type": "object"
57
+ },
58
+ "nested": {
59
+ "type": "array"
60
+ },
61
+ "consent": {
62
+ "type": "object"
63
+ },
64
+ "id": {
65
+ "type": "string"
66
+ },
67
+ "trigger": {
68
+ "type": "string"
69
+ },
70
+ "timestamp": {
71
+ "type": "number"
72
+ },
73
+ "timing": {
74
+ "type": "number"
75
+ },
76
+ "group": {
77
+ "type": "string"
78
+ },
79
+ "count": {
80
+ "type": "number"
81
+ },
82
+ "version": {
83
+ "type": "object",
84
+ "required": [
85
+ "source",
86
+ "tagging"
87
+ ],
88
+ "properties": {
89
+ "source": {
90
+ "type": "string"
91
+ },
92
+ "tagging": {
93
+ "type": "number"
94
+ }
95
+ }
96
+ },
97
+ "source": {
98
+ "type": "object",
99
+ "required": [
100
+ "type",
101
+ "id",
102
+ "previous_id"
103
+ ],
104
+ "properties": {
105
+ "type": {
106
+ "type": "string"
107
+ },
108
+ "id": {
109
+ "type": "string"
110
+ },
111
+ "previous_id": {
112
+ "type": "string"
113
+ }
114
+ }
115
+ }
116
+ }
117
+ },
118
+ "settings": {
119
+ "type": "object",
120
+ "properties": {
121
+ "format": {
122
+ "type": "boolean",
123
+ "description": "Validate full WalkerOS.Event structure. Pre-compiled at init.",
124
+ "default": true
125
+ },
126
+ "contract": {
127
+ "type": "object",
128
+ "description": "Event-specific validation rules. Entity/action keyed, supports wildcards."
129
+ }
130
+ }
131
+ }
132
+ },
133
+ "examples": {
134
+ "step": {
135
+ "contractValidationPass": {
136
+ "description": "Contract validation passes when event data matches the entity.action JSON Schema",
137
+ "in": {
138
+ "name": "order complete",
139
+ "data": {
140
+ "id": "0rd3r1d",
141
+ "total": 555,
142
+ "currency": "EUR"
143
+ },
144
+ "context": {
145
+ "shopping": [
146
+ "complete",
147
+ 0
148
+ ]
149
+ },
150
+ "globals": {
151
+ "pagegroup": "shop"
152
+ },
153
+ "custom": {
154
+ "completely": "random"
155
+ },
156
+ "user": {
157
+ "id": "us3r",
158
+ "device": "c00k13",
159
+ "session": "s3ss10n"
160
+ },
161
+ "nested": [
162
+ {
163
+ "entity": "product",
164
+ "data": {
165
+ "id": "ers",
166
+ "name": "Everyday Ruck Snack",
167
+ "color": "black",
168
+ "size": "l",
169
+ "price": 420
170
+ },
171
+ "context": {
172
+ "shopping": [
173
+ "complete",
174
+ 0
175
+ ]
176
+ },
177
+ "nested": []
178
+ },
179
+ {
180
+ "entity": "product",
181
+ "data": {
182
+ "id": "cc",
183
+ "name": "Cool Cap",
184
+ "size": "one size",
185
+ "price": 42
186
+ },
187
+ "context": {
188
+ "shopping": [
189
+ "complete",
190
+ 0
191
+ ]
192
+ },
193
+ "nested": []
194
+ },
195
+ {
196
+ "entity": "gift",
197
+ "data": {
198
+ "name": "Surprise"
199
+ },
200
+ "context": {
201
+ "shopping": [
202
+ "complete",
203
+ 0
204
+ ]
205
+ },
206
+ "nested": []
207
+ }
208
+ ],
209
+ "consent": {
210
+ "functional": true
211
+ },
212
+ "id": "1700000800-gr0up-1",
213
+ "trigger": "load",
214
+ "entity": "order",
215
+ "action": "complete",
216
+ "timestamp": 1700000800,
217
+ "timing": 3.14,
218
+ "group": "gr0up",
219
+ "count": 1,
220
+ "version": {
221
+ "source": "3.0.1",
222
+ "tagging": 1
223
+ },
224
+ "source": {
225
+ "type": "web",
226
+ "id": "https://shop.example.com",
227
+ "previous_id": ""
228
+ }
229
+ },
230
+ "out": {
231
+ "event": {
232
+ "name": "order complete",
233
+ "data": {
234
+ "id": "0rd3r1d",
235
+ "total": 555,
236
+ "currency": "EUR"
237
+ },
238
+ "context": {
239
+ "shopping": [
240
+ "complete",
241
+ 0
242
+ ]
243
+ },
244
+ "globals": {
245
+ "pagegroup": "shop"
246
+ },
247
+ "custom": {
248
+ "completely": "random"
249
+ },
250
+ "user": {
251
+ "id": "us3r",
252
+ "device": "c00k13",
253
+ "session": "s3ss10n"
254
+ },
255
+ "nested": [
256
+ {
257
+ "entity": "product",
258
+ "data": {
259
+ "id": "ers",
260
+ "name": "Everyday Ruck Snack",
261
+ "color": "black",
262
+ "size": "l",
263
+ "price": 420
264
+ },
265
+ "context": {
266
+ "shopping": [
267
+ "complete",
268
+ 0
269
+ ]
270
+ },
271
+ "nested": []
272
+ },
273
+ {
274
+ "entity": "product",
275
+ "data": {
276
+ "id": "cc",
277
+ "name": "Cool Cap",
278
+ "size": "one size",
279
+ "price": 42
280
+ },
281
+ "context": {
282
+ "shopping": [
283
+ "complete",
284
+ 0
285
+ ]
286
+ },
287
+ "nested": []
288
+ },
289
+ {
290
+ "entity": "gift",
291
+ "data": {
292
+ "name": "Surprise"
293
+ },
294
+ "context": {
295
+ "shopping": [
296
+ "complete",
297
+ 0
298
+ ]
299
+ },
300
+ "nested": []
301
+ }
302
+ ],
303
+ "consent": {
304
+ "functional": true
305
+ },
306
+ "id": "1700000800-gr0up-1",
307
+ "trigger": "load",
308
+ "entity": "order",
309
+ "action": "complete",
310
+ "timestamp": 1700000800,
311
+ "timing": 3.14,
312
+ "group": "gr0up",
313
+ "count": 1,
314
+ "version": {
315
+ "source": "3.0.1",
316
+ "tagging": 1
317
+ },
318
+ "source": {
319
+ "type": "web",
320
+ "id": "https://shop.example.com",
321
+ "previous_id": ""
322
+ }
323
+ }
324
+ }
325
+ },
326
+ "invalidFormat": {
327
+ "in": {
328
+ "name": "invalid",
329
+ "data": {}
330
+ },
331
+ "out": false
332
+ },
333
+ "validEvent": {
334
+ "in": {
335
+ "name": "product view",
336
+ "data": {
337
+ "id": "SKU-100",
338
+ "name": "Trail Runner Pro",
339
+ "price": 129.99
340
+ },
341
+ "context": {
342
+ "shopping": [
343
+ "detail",
344
+ 0
345
+ ]
346
+ },
347
+ "globals": {
348
+ "pagegroup": "shop"
349
+ },
350
+ "custom": {
351
+ "completely": "random"
352
+ },
353
+ "user": {
354
+ "id": "us3r",
355
+ "device": "c00k13",
356
+ "session": "s3ss10n"
357
+ },
358
+ "nested": [],
359
+ "consent": {
360
+ "functional": true
361
+ },
362
+ "id": "1700000700-gr0up-1",
363
+ "trigger": "load",
364
+ "entity": "product",
365
+ "action": "view",
366
+ "timestamp": 1700000700,
367
+ "timing": 3.14,
368
+ "group": "gr0up",
369
+ "count": 1,
370
+ "version": {
371
+ "source": "3.0.1",
372
+ "tagging": 1
373
+ },
374
+ "source": {
375
+ "type": "web",
376
+ "id": "https://example.com",
377
+ "previous_id": ""
378
+ }
379
+ },
380
+ "out": {
381
+ "event": {
382
+ "name": "product view",
383
+ "data": {
384
+ "id": "SKU-100",
385
+ "name": "Trail Runner Pro",
386
+ "price": 129.99
387
+ },
388
+ "context": {
389
+ "shopping": [
390
+ "detail",
391
+ 0
392
+ ]
393
+ },
394
+ "globals": {
395
+ "pagegroup": "shop"
396
+ },
397
+ "custom": {
398
+ "completely": "random"
399
+ },
400
+ "user": {
401
+ "id": "us3r",
402
+ "device": "c00k13",
403
+ "session": "s3ss10n"
404
+ },
405
+ "nested": [],
406
+ "consent": {
407
+ "functional": true
408
+ },
409
+ "id": "1700000700-gr0up-1",
410
+ "trigger": "load",
411
+ "entity": "product",
412
+ "action": "view",
413
+ "timestamp": 1700000700,
414
+ "timing": 3.14,
415
+ "group": "gr0up",
416
+ "count": 1,
417
+ "version": {
418
+ "source": "3.0.1",
419
+ "tagging": 1
420
+ },
421
+ "source": {
422
+ "type": "web",
423
+ "id": "https://example.com",
424
+ "previous_id": ""
425
+ }
426
+ }
427
+ }
428
+ }
429
+ }
430
+ }
431
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@walkeros/transformer-validator",
3
3
  "description": "Event validation transformer for walkerOS using AJV and JSON Schema",
4
- "version": "3.0.0",
4
+ "version": "3.0.2",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -23,20 +23,19 @@
23
23
  ],
24
24
  "scripts": {
25
25
  "build": "tsup --silent",
26
- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
26
+ "clean": "rm -rf .turbo && rm -rf dist",
27
27
  "dev": "jest --watchAll --colors",
28
- "lint": "tsc --noEmit && eslint \"**/*.ts*\"",
28
+ "typecheck": "tsc --noEmit",
29
+ "lint": "eslint \"**/*.ts*\"",
29
30
  "test": "jest",
30
31
  "update": "npx npm-check-updates -u && npm update"
31
32
  },
32
33
  "dependencies": {
33
- "ajv": "^8.17.1"
34
- },
35
- "peerDependencies": {
36
- "@walkeros/core": "^1.2.0"
34
+ "ajv": "^8.17.1",
35
+ "@walkeros/core": "^3.0.2"
37
36
  },
38
37
  "devDependencies": {
39
- "@walkeros/core": "1.2.0"
38
+ "@walkeros/core": "^3.0.2"
40
39
  },
41
40
  "repository": {
42
41
  "url": "git+https://github.com/elbwalker/walkerOS.git",
@@ -47,13 +46,18 @@
47
46
  "bugs": {
48
47
  "url": "https://github.com/elbwalker/walkerOS/issues"
49
48
  },
49
+ "walkerOS": {
50
+ "type": "transformer",
51
+ "docs": "https://www.walkeros.io/docs/transformers/validator"
52
+ },
50
53
  "keywords": [
51
- "walker",
52
54
  "walkerOS",
55
+ "walkerOS-transformer",
53
56
  "transformer",
54
57
  "validator",
55
58
  "ajv",
56
- "json-schema"
59
+ "json-schema",
60
+ "analytics"
57
61
  ],
58
62
  "funding": [
59
63
  {