@walkeros/transformer-validator 2.1.0 → 2.1.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/dist/dev.js CHANGED
@@ -1 +1 @@
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})},n={};p(n,{examples:()=>s,formatSchema:()=>a,schemas:()=>g,settingsSchema:()=>m}),module.exports=(e=n,((e,p,n,a)=>{if(p&&"object"==typeof p||"function"==typeof p)for(let s of i(p))o.call(e,s)||s===n||t(e,s,{get:()=>p[s],enumerable:!(a=r(p,s))||a.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a={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,{invalidFormat:()=>d,validEvent:()=>y});var u=require("@walkeros/core"),y={in:(0,u.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:(0,u.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:""}})},d={in:{name:"invalid",data:{}},out:!1},m={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:a,settings:m};//# 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})},n={};p(n,{examples:()=>s,formatSchema:()=>a,schemas:()=>g,settingsSchema:()=>m}),module.exports=(e=n,((e,p,n,a)=>{if(p&&"object"==typeof p||"function"==typeof p)for(let s of i(p))o.call(e,s)||s===n||t(e,s,{get:()=>p[s],enumerable:!(a=r(p,s))||a.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a={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,{invalidFormat:()=>d,validEvent:()=>y});var u=require("@walkeros/core"),y={in:(0,u.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,u.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:""}})}},d={in:{name:"invalid",data:{}},out:!1},m={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:a,settings:m};//# sourceMappingURL=dev.js.map
package/dist/dev.js.map CHANGED
@@ -1 +1 @@
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: 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\nexport const invalidFormat: Flow.StepExample = {\n in: {\n name: 'invalid',\n data: {},\n },\n out: false,\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;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C;AAAA,EAC7C,IAAI;AAAA,IACF,MAAM;AAAA,IACN,MAAM,CAAC;AAAA,EACT;AAAA,EACA,KAAK;AACP;;;AHVO,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"],"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,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G;AAAA,EACpE,CAAC;AAAA,EACD,KAAK;AAAA,IACH,WAAO,sBAAS,gBAAgB;AAAA,MAC9B,WAAW;AAAA,MACX,MAAM,EAAE,IAAI,WAAW,MAAM,oBAAoB,OAAO,OAAO;AAAA,MAC/D,QAAQ,EAAE,MAAM,OAAO,IAAI,uBAAuB,aAAa,GAAG;AAAA,IACpE,CAAC;AAAA,EACH;AACF;AAEO,IAAM,gBAAkC;AAAA,EAC7C,IAAI;AAAA,IACF,MAAM;AAAA,IACN,MAAM,CAAC;AAAA,EACT;AAAA,EACA,KAAK;AACP;;;AHZO,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 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:()=>p});var p={};t(p,{invalidFormat:()=>a,validEvent:()=>n});import{getEvent as o}from"@walkeros/core";var n={in:o("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:o("product view",{timestamp:1700000700,data:{id:"SKU-100",name:"Trail Runner Pro",price:129.99},source:{type:"web",id:"https://example.com",previous_id:""}})},a={in:{name:"invalid",data:{}},out:!1},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:r,settings:s};export{i as examples,r as formatSchema,c as schemas,s 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:()=>p});var p={};t(p,{invalidFormat:()=>a,validEvent:()=>n});import{getEvent as o}from"@walkeros/core";var n={in:o("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:o("product view",{timestamp:1700000700,data:{id:"SKU-100",name:"Trail Runner Pro",price:129.99},source:{type:"web",id:"https://example.com",previous_id:""}})}},a={in:{name:"invalid",data:{}},out:!1},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:r,settings:s};export{i as examples,r as formatSchema,c as schemas,s as settingsSchema};//# sourceMappingURL=dev.mjs.map
package/dist/dev.mjs.map CHANGED
@@ -1 +1 @@
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: 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\nexport const invalidFormat: Flow.StepExample = {\n in: {\n name: 'invalid',\n data: {},\n },\n out: false,\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 './examples';\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,E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,CAAC;AAAA,EACT;AAAA,EACA,KAAK;AACP;;;ACVO,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","/**\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"],"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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,WAAW,MAAM,oBAAoB,OAAO,OAAO;AAAA,MAC/D,QAAQ,EAAE,MAAM,OAAO,IAAI,uBAAuB,aAAa,GAAG;AAAA,IACpE,CAAC;AAAA,EACH;AACF;AAEO,IAAM,gBAAkC;AAAA,EAC7C,IAAI;AAAA,IACF,MAAM;AAAA,IACN,MAAM,CAAC;AAAA,EACT;AAAA,EACA,KAAK;AACP;;;ACZO,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/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 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{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,SA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,IAEA,MAAM,KAAK,OAAOC,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,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 {\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,EAA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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,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,EAAE,MAAM;AAAA,IACjB;AAAA,EACF;AACF;","names":["Ajv","context"]}
package/dist/index.mjs 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";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{event:e}}}};export{o as default,o 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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C;AAGtD,QAAM,kBAAkB,SAAS,IAAI,QAAQ,YAAY,IAAI;AAI7D,QAAM,qBAAqB,oBAAI,QAAsC;AAErE,WAAS,qBAAqB,QAAoB;AAChD,QAAI,CAAC,mBAAmB,IAAI,MAAM,GAAG;AAEnC,YAAM,aAAa,EAAE,MAAM,UAAU,GAAG,OAAO;AAC/C,yBAAmB,IAAI,QAAQ,IAAI,QAAQ,UAAU,CAAC;AAAA,IACxD;AACA,WAAO,mBAAmB,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 { 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,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/C,yBAAmB,IAAI,QAAQ,IAAI,QAAQ,UAAU,CAAC;AAAA,IACxD;AACA,WAAO,mBAAmB,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,EAAE,MAAM;AAAA,IACjB;AAAA,EACF;AACF;","names":["context"]}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$meta": {
3
3
  "package": "@walkeros/transformer-validator",
4
- "version": "2.0.1",
4
+ "version": "2.1.0",
5
5
  "type": "transformer"
6
6
  },
7
7
  "schemas": {
@@ -175,7 +175,7 @@
175
175
  "group": "gr0up",
176
176
  "count": 1,
177
177
  "version": {
178
- "source": "2.0.1",
178
+ "source": "2.1.0",
179
179
  "tagging": 1
180
180
  },
181
181
  "source": {
@@ -185,49 +185,51 @@
185
185
  }
186
186
  },
187
187
  "out": {
188
- "name": "product view",
189
- "data": {
190
- "id": "SKU-100",
191
- "name": "Trail Runner Pro",
192
- "price": 129.99
193
- },
194
- "context": {
195
- "shopping": [
196
- "detail",
197
- 0
198
- ]
199
- },
200
- "globals": {
201
- "pagegroup": "shop"
202
- },
203
- "custom": {
204
- "completely": "random"
205
- },
206
- "user": {
207
- "id": "us3r",
208
- "device": "c00k13",
209
- "session": "s3ss10n"
210
- },
211
- "nested": [],
212
- "consent": {
213
- "functional": true
214
- },
215
- "id": "1700000700-gr0up-1",
216
- "trigger": "load",
217
- "entity": "product",
218
- "action": "view",
219
- "timestamp": 1700000700,
220
- "timing": 3.14,
221
- "group": "gr0up",
222
- "count": 1,
223
- "version": {
224
- "source": "2.0.1",
225
- "tagging": 1
226
- },
227
- "source": {
228
- "type": "web",
229
- "id": "https://example.com",
230
- "previous_id": ""
188
+ "event": {
189
+ "name": "product view",
190
+ "data": {
191
+ "id": "SKU-100",
192
+ "name": "Trail Runner Pro",
193
+ "price": 129.99
194
+ },
195
+ "context": {
196
+ "shopping": [
197
+ "detail",
198
+ 0
199
+ ]
200
+ },
201
+ "globals": {
202
+ "pagegroup": "shop"
203
+ },
204
+ "custom": {
205
+ "completely": "random"
206
+ },
207
+ "user": {
208
+ "id": "us3r",
209
+ "device": "c00k13",
210
+ "session": "s3ss10n"
211
+ },
212
+ "nested": [],
213
+ "consent": {
214
+ "functional": true
215
+ },
216
+ "id": "1700000700-gr0up-1",
217
+ "trigger": "load",
218
+ "entity": "product",
219
+ "action": "view",
220
+ "timestamp": 1700000700,
221
+ "timing": 3.14,
222
+ "group": "gr0up",
223
+ "count": 1,
224
+ "version": {
225
+ "source": "2.1.0",
226
+ "tagging": 1
227
+ },
228
+ "source": {
229
+ "type": "web",
230
+ "id": "https://example.com",
231
+ "previous_id": ""
232
+ }
231
233
  }
232
234
  }
233
235
  }
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": "2.1.0",
4
+ "version": "2.1.1",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -32,10 +32,10 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "ajv": "^8.17.1",
35
- "@walkeros/core": "^2.1.0"
35
+ "@walkeros/core": "^2.1.1"
36
36
  },
37
37
  "devDependencies": {
38
- "@walkeros/core": "^2.1.0"
38
+ "@walkeros/core": "^2.1.1"
39
39
  },
40
40
  "repository": {
41
41
  "url": "git+https://github.com/elbwalker/walkerOS.git",