@walkeros/transformer-validator 1.0.0 → 2.0.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/index.d.mts CHANGED
@@ -56,4 +56,4 @@ interface ValidatorSettings {
56
56
  */
57
57
  declare const transformerValidator: Transformer.Init<Transformer.Types<ValidatorSettings>>;
58
58
 
59
- export { type Contract, type ContractRule, type JsonSchema, type ValidatorSettings, transformerValidator };
59
+ export { type Contract, type ContractRule, type JsonSchema, type ValidatorSettings, transformerValidator as default, transformerValidator };
package/dist/index.d.ts CHANGED
@@ -56,4 +56,4 @@ interface ValidatorSettings {
56
56
  */
57
57
  declare const transformerValidator: Transformer.Init<Transformer.Types<ValidatorSettings>>;
58
58
 
59
- export { type Contract, type ContractRule, type JsonSchema, type ValidatorSettings, transformerValidator };
59
+ export { type Contract, type ContractRule, 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,{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 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","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;;;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,SAA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;AAAA,IACN;AAAA,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,I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M,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"]}
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 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 e}}};export{o as default,o as transformerValidator};//# sourceMappingURL=index.mjs.map
@@ -0,0 +1,132 @@
1
+ {
2
+ "$meta": {
3
+ "package": "@walkeros/transformer-validator",
4
+ "version": "2.0.0",
5
+ "type": "transformer"
6
+ },
7
+ "schemas": {
8
+ "format": {
9
+ "type": "object",
10
+ "required": [
11
+ "name",
12
+ "entity",
13
+ "action",
14
+ "data",
15
+ "context",
16
+ "globals",
17
+ "custom",
18
+ "user",
19
+ "nested",
20
+ "consent",
21
+ "id",
22
+ "trigger",
23
+ "timestamp",
24
+ "timing",
25
+ "group",
26
+ "count",
27
+ "version",
28
+ "source"
29
+ ],
30
+ "properties": {
31
+ "name": {
32
+ "type": "string",
33
+ "pattern": "^\\S+ \\S+$"
34
+ },
35
+ "entity": {
36
+ "type": "string"
37
+ },
38
+ "action": {
39
+ "type": "string"
40
+ },
41
+ "data": {
42
+ "type": "object"
43
+ },
44
+ "context": {
45
+ "type": "object"
46
+ },
47
+ "globals": {
48
+ "type": "object"
49
+ },
50
+ "custom": {
51
+ "type": "object"
52
+ },
53
+ "user": {
54
+ "type": "object"
55
+ },
56
+ "nested": {
57
+ "type": "array"
58
+ },
59
+ "consent": {
60
+ "type": "object"
61
+ },
62
+ "id": {
63
+ "type": "string"
64
+ },
65
+ "trigger": {
66
+ "type": "string"
67
+ },
68
+ "timestamp": {
69
+ "type": "number"
70
+ },
71
+ "timing": {
72
+ "type": "number"
73
+ },
74
+ "group": {
75
+ "type": "string"
76
+ },
77
+ "count": {
78
+ "type": "number"
79
+ },
80
+ "version": {
81
+ "type": "object",
82
+ "required": [
83
+ "source",
84
+ "tagging"
85
+ ],
86
+ "properties": {
87
+ "source": {
88
+ "type": "string"
89
+ },
90
+ "tagging": {
91
+ "type": "number"
92
+ }
93
+ }
94
+ },
95
+ "source": {
96
+ "type": "object",
97
+ "required": [
98
+ "type",
99
+ "id",
100
+ "previous_id"
101
+ ],
102
+ "properties": {
103
+ "type": {
104
+ "type": "string"
105
+ },
106
+ "id": {
107
+ "type": "string"
108
+ },
109
+ "previous_id": {
110
+ "type": "string"
111
+ }
112
+ }
113
+ }
114
+ }
115
+ },
116
+ "settings": {
117
+ "type": "object",
118
+ "properties": {
119
+ "format": {
120
+ "type": "boolean",
121
+ "description": "Validate full WalkerOS.Event structure. Pre-compiled at init.",
122
+ "default": true
123
+ },
124
+ "contract": {
125
+ "type": "object",
126
+ "description": "Event-specific validation rules. Entity/action keyed, supports wildcards."
127
+ }
128
+ }
129
+ }
130
+ },
131
+ "examples": {}
132
+ }
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": "1.0.0",
4
+ "version": "2.0.1",
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": "^0.7.0"
34
+ "ajv": "^8.17.1",
35
+ "@walkeros/core": "^2.0.0"
37
36
  },
38
37
  "devDependencies": {
39
- "@walkeros/core": "0.7.0"
38
+ "@walkeros/core": "^2.0.0"
40
39
  },
41
40
  "repository": {
42
41
  "url": "git+https://github.com/elbwalker/walkerOS.git",
@@ -47,13 +46,17 @@
47
46
  "bugs": {
48
47
  "url": "https://github.com/elbwalker/walkerOS/issues"
49
48
  },
49
+ "walkerOS": {
50
+ "type": "transformer"
51
+ },
50
52
  "keywords": [
51
- "walker",
52
53
  "walkerOS",
54
+ "walkerOS-transformer",
53
55
  "transformer",
54
56
  "validator",
55
57
  "ajv",
56
- "json-schema"
58
+ "json-schema",
59
+ "analytics"
57
60
  ],
58
61
  "funding": [
59
62
  {