@mkrause/lifecycle-rest
Advanced tools
+1
-0
@@ -9,2 +9,3 @@ | ||
| - Introduce `RestApi.decorateMethod()` as alternative for `@RestApi.method` legacy decorator syntax. | ||
| - [0.5.4] Export `DecodeError` | ||
@@ -11,0 +12,0 @@ - v0.4.x |
+8
-0
@@ -6,2 +6,8 @@ "use strict"; | ||
| }); | ||
| Object.defineProperty(exports, "DecodeError", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _Schema.DecodeError; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "resourceDef", { | ||
@@ -39,2 +45,4 @@ enumerable: true, | ||
| var _Schema = require("./schema/Schema"); | ||
| var _Resource = require("./loader/Resource.js"); | ||
@@ -41,0 +49,0 @@ |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.ts"],"names":["redux","middleware","reduxMiddleware","reducer","reduxReduce"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AAEA;;AAEA;;AAEA;;AACA;;AAOA;;;;AANO,MAAMA,KAAK,GAAG;AAAEC,EAAAA,UAAU,EAAEC,mBAAd;AAA+BC,EAAAA,OAAO,EAAEC;AAAxC,CAAd","sourcesContent":["\nexport { resourceDef } from './loader/Resource.js';\n\nexport { default as createAgent } from './agent.js';\n\nexport { default as RestApi } from './loader/RestApi.js';\n\nimport reduxMiddleware from './redux/middleware.js';\nimport reduxReduce from './redux/reducer.js';\nexport const redux = { middleware: reduxMiddleware, reducer: reduxReduce };\n\nexport { default as default } from './loader/RestApi.js';\n\n\n// Re-export from lifecycle-loader, for convenience\nexport { status } from '@mkrause/lifecycle-loader';\n"],"file":"index.js"} | ||
| {"version":3,"sources":["../src/index.ts"],"names":["redux","middleware","reduxMiddleware","reducer","reduxReduce"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AACA;;AAEA;;AAEA;;AAEA;;AACA;;AAOA;;;;AANO,MAAMA,KAAK,GAAG;AAAEC,EAAAA,UAAU,EAAEC,mBAAd;AAA+BC,EAAAA,OAAO,EAAEC;AAAxC,CAAd","sourcesContent":["\nexport { DecodeError } from './schema/Schema';\nexport { resourceDef } from './loader/Resource.js';\n\nexport { default as createAgent } from './agent.js';\n\nexport { default as RestApi } from './loader/RestApi.js';\n\nimport reduxMiddleware from './redux/middleware.js';\nimport reduxReduce from './redux/reducer.js';\nexport const redux = { middleware: reduxMiddleware, reducer: reduxReduce };\n\nexport { default as default } from './loader/RestApi.js';\n\n\n// Re-export from lifecycle-loader, for convenience\nexport { status } from '@mkrause/lifecycle-loader';\n"],"file":"index.js"} |
@@ -22,2 +22,4 @@ "use strict"; | ||
| //import { isLeft } from 'fp-ts/lib/Either'; | ||
| //import { Errors as ValidationErrors, ValidationError } from 'io-ts'; | ||
| const makeAdapter = (resource, schema = resource.schema) => ({ | ||
@@ -24,0 +26,0 @@ with(schema) { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../../src/loader/Adapter.ts"],"names":["makeAdapter","resource","schema","with","parse","response","status","data","decode","input","agent","adapter","report","encode","instance","decodeResult","_tag","right","errors","left","PathReporter","message","map","error","join","DecodeError","format","item","partial","t","props","getKey","id","TypeError"],"mappings":";;;;;;;AACA;;AAEA;;AAOA;;AAGA;;;;;;;;AAGA,MAAMA,WAAW,GAAG,CAA4BC,QAA5B,EAA8DC,MAAU,GAAGD,QAAQ,CAACC,MAApF,MAAgG;AAChHC,EAAAA,IAAI,CAACD,MAAD,EAAkB;AAClB,WAAOF,WAAW,CAACC,QAAD,EAAWC,MAAX,CAAlB;AACH,GAH+G;;AAKhHE,EAAAA,KAAK,CAACC,QAAD,EAA2B;AAC5B,QAAIA,QAAQ,CAACC,MAAT,KAAoB,GAAxB,EAA6B;AAAE,aAAO,IAAP;AAAc;;AAC7C,WAAOD,QAAQ,CAACE,IAAhB;AACH,GAR+G;;AAUhHC,EAAAA,MAAM,CAACC,KAAD,EAAkB;AACpB,UAAM;AAAEC,MAAAA,KAAF;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AM,IAAIC,SAAJ,CAAc,wBAAK,yBAAwBnB,QAAS,EAApD,CAAN;AACH;AAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AA7EoH,CAAhG,CAApB,C,CAgFA;AACA;AACA;;;eAGed,W","sourcesContent":["\nimport $msg from 'message-tag';\n\nimport { Schema, DecodeError } from '../schema/Schema.js';\n\nimport type { Resource } from './Resource.js';\nimport { ResourceDefinition } from './Resource.js';\n\nimport { AxiosResponse } from 'axios';\n\nimport * as t from 'io-ts';\nimport { isLeft } from 'fp-ts/lib/Either';\nimport { Errors as ValidationErrors, ValidationError } from 'io-ts';\nimport { PathReporter } from 'io-ts/lib/PathReporter.js';\n\n\nconst makeAdapter = <S extends Schema<unknown>>(resource : ResourceDefinition<S>, schema : S = resource.schema) => ({\n with(schema : Schema) {\n return makeAdapter(resource, schema);\n },\n \n parse(response : AxiosResponse) {\n if (response.status === 204) { return null; }\n return response.data;\n },\n \n decode(input : unknown) {\n const { agent, adapter } = resource;\n \n return adapter.report(schema.decode(input));\n },\n \n encode(instance : unknown) {\n const { agent, adapter } = resource;\n \n return schema.encode(instance);\n },\n \n report(decodeResult : t.Validation<unknown>) {\n if (decodeResult._tag === 'Right') {\n return decodeResult.right;\n } else {\n const errors = decodeResult.left;\n const report = PathReporter.report(decodeResult);\n \n const message = `Failed to decode response:\\n` + report.map(error =>\n `\\n- ${error}`\n ).join('');\n \n throw new DecodeError(message, errors);\n }\n },\n \n format(item : unknown) { return item },\n \n partial() {\n if ('props' in schema) {\n return t.partial((schema as any).props);\n } else {\n return schema;\n }\n },\n \n getKey(instance : t.TypeOf<Schema>) {\n if (typeof instance === 'object' && instance !== null && 'id' in instance) {\n return (instance as { id : unknown }).id;\n }\n \n throw new TypeError($msg`Unable to get key for ${instance}`);\n },\n \n /* TODO\n keyOf() {\n // If the schema is `any`, try to find a default `id` property?\n if (schema.name === 'Unknown') { // TEMP\n const IdType = t.type({ id: t.any });\n return new Type(\n 'keyof ' + IdType.name,\n IdType.is,\n (input : t.InputOf<typeof IdType>, context : t.Context) => {\n const e = IdType.validate(input, context);\n if (isLeft(e)) {\n return e;\n }\n \n return e.right.id;\n },\n (instance : unknown) => instance,\n );\n }\n \n return schema\n },\n */\n});\n\n// Get the return type of `Adapter`\n// FIXME: currently this leads to a circular reference\n//export type AdapterT = typeof Adapter extends <S extends Schema>(...args : never[]) => infer R ? R : never;\nexport type AdapterT = any;\n\nexport default makeAdapter;\n"],"file":"Adapter.js"} | ||
| {"version":3,"sources":["../../src/loader/Adapter.ts"],"names":["makeAdapter","resource","schema","with","parse","response","status","data","decode","input","agent","adapter","report","encode","instance","decodeResult","_tag","right","errors","left","PathReporter","message","map","error","join","DecodeError","format","item","partial","t","props","getKey","id","TypeError"],"mappings":";;;;;;;AACA;;AAEA;;AAOA;;AAGA;;;;;;;;AAFA;AACA;AAIA,MAAMA,WAAW,GAAG,CAA4BC,QAA5B,EAA8DC,MAAU,GAAGD,QAAQ,CAACC,MAApF,MAAgG;AAChHC,EAAAA,IAAI,CAACD,MAAD,EAAkB;AAClB,WAAOF,WAAW,CAACC,QAAD,EAAWC,MAAX,CAAlB;AACH,GAH+G;;AAKhHE,EAAAA,KAAK,CAACC,QAAD,EAA2B;AAC5B,QAAIA,QAAQ,CAACC,MAAT,KAAoB,GAAxB,EAA6B;AAAE,aAAO,IAAP;AAAc;;AAC7C,WAAOD,QAAQ,CAACE,IAAhB;AACH,GAR+G;;AAUhHC,EAAAA,MAAM,CAACC,KAAD,EAAkB;AACpB,UAAM;AAAEC,MAAAA,KAAF;AAASC,MAAAA;AAAT,QAAqBV,QAA3B;AAEA,WAAOU,OAAO,CAACC,MAAR,CAAeV,MAAM,CAACM,MAAP,CAAcC,KAAd,CAAf,CAAP;AACH,GAd+G;;AAgBhHI,EAAAA,MAAM,CAACC,QAAD,EAAqB;AACvB,UAAM;AAAEJ,MAAAA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B,C,CAgFA;AACA;AACA;;;eAGed,W","sourcesContent":["\nimport $msg from 'message-tag';\n\nimport { Schema, DecodeError } from '../schema/Schema.js';\n\nimport type { Resource } from './Resource.js';\nimport { ResourceDefinition } from './Resource.js';\n\nimport { AxiosResponse } from 'axios';\n\nimport * as t from 'io-ts';\n//import { isLeft } from 'fp-ts/lib/Either';\n//import { Errors as ValidationErrors, ValidationError } from 'io-ts';\nimport { PathReporter } from 'io-ts/lib/PathReporter.js';\n\n\nconst makeAdapter = <S extends Schema<unknown>>(resource : ResourceDefinition<S>, schema : S = resource.schema) => ({\n with(schema : Schema) {\n return makeAdapter(resource, schema);\n },\n \n parse(response : AxiosResponse) {\n if (response.status === 204) { return null; }\n return response.data;\n },\n \n decode(input : unknown) {\n const { agent, adapter } = resource;\n \n return adapter.report(schema.decode(input));\n },\n \n encode(instance : unknown) {\n const { agent, adapter } = resource;\n \n return schema.encode(instance);\n },\n \n report(decodeResult : t.Validation<unknown>) {\n if (decodeResult._tag === 'Right') {\n return decodeResult.right;\n } else {\n const errors = decodeResult.left;\n const report = PathReporter.report(decodeResult);\n \n const message = `Failed to decode response:\\n` + report.map(error =>\n `\\n- ${error}`\n ).join('');\n \n throw new DecodeError(message, errors);\n }\n },\n \n format(item : unknown) { return item },\n \n partial() {\n if ('props' in schema) {\n return t.partial((schema as any).props);\n } else {\n return schema;\n }\n },\n \n getKey(instance : t.TypeOf<Schema>) {\n if (typeof instance === 'object' && instance !== null && 'id' in instance) {\n return (instance as { id : unknown }).id;\n }\n \n throw new TypeError($msg`Unable to get key for ${instance}`);\n },\n \n /* TODO\n keyOf() {\n // If the schema is `any`, try to find a default `id` property?\n if (schema.name === 'Unknown') { // TEMP\n const IdType = t.type({ id: t.any });\n return new Type(\n 'keyof ' + IdType.name,\n IdType.is,\n (input : t.InputOf<typeof IdType>, context : t.Context) => {\n const e = IdType.validate(input, context);\n if (isLeft(e)) {\n return e;\n }\n \n return e.right.id;\n },\n (instance : unknown) => instance,\n );\n }\n \n return schema\n },\n */\n});\n\n// Get the return type of `Adapter`\n// FIXME: currently this leads to a circular reference\n//export type AdapterT = typeof Adapter extends <S extends Schema>(...args : never[]) => infer R ? R : never;\nexport type AdapterT = any;\n\nexport default makeAdapter;\n"],"file":"Adapter.js"} |
+1
-0
@@ -0,1 +1,2 @@ | ||
| export { DecodeError } from './schema/Schema'; | ||
| export { resourceDef } from './loader/Resource.js'; | ||
@@ -2,0 +3,0 @@ export { default as createAgent } from './agent.js'; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.ts"],"names":["resourceDef","default","createAgent","RestApi","reduxMiddleware","reduxReduce","redux","middleware","reducer","status"],"mappings":"AACA,SAASA,WAAT,QAA4B,sBAA5B;AAEA,SAASC,OAAO,IAAIC,WAApB,QAAuC,YAAvC;AAEA,SAASD,OAAO,IAAIE,OAApB,QAAmC,qBAAnC;AAEA,OAAOC,eAAP,MAA4B,uBAA5B;AACA,OAAOC,WAAP,MAAwB,oBAAxB;AACA,OAAO,MAAMC,KAAK,GAAG;AAAEC,EAAAA,UAAU,EAAEH,eAAd;AAA+BI,EAAAA,OAAO,EAAEH;AAAxC,CAAd;AAEP,SAASJ,OAAT,QAAmC,qBAAnC,C,CAGA;;AACA,SAASQ,MAAT,QAAuB,2BAAvB","sourcesContent":["\nexport { resourceDef } from './loader/Resource.js';\n\nexport { default as createAgent } from './agent.js';\n\nexport { default as RestApi } from './loader/RestApi.js';\n\nimport reduxMiddleware from './redux/middleware.js';\nimport reduxReduce from './redux/reducer.js';\nexport const redux = { middleware: reduxMiddleware, reducer: reduxReduce };\n\nexport { default as default } from './loader/RestApi.js';\n\n\n// Re-export from lifecycle-loader, for convenience\nexport { status } from '@mkrause/lifecycle-loader';\n"],"file":"index.js"} | ||
| {"version":3,"sources":["../src/index.ts"],"names":["DecodeError","resourceDef","default","createAgent","RestApi","reduxMiddleware","reduxReduce","redux","middleware","reducer","status"],"mappings":"AACA,SAASA,WAAT,QAA4B,iBAA5B;AACA,SAASC,WAAT,QAA4B,sBAA5B;AAEA,SAASC,OAAO,IAAIC,WAApB,QAAuC,YAAvC;AAEA,SAASD,OAAO,IAAIE,OAApB,QAAmC,qBAAnC;AAEA,OAAOC,eAAP,MAA4B,uBAA5B;AACA,OAAOC,WAAP,MAAwB,oBAAxB;AACA,OAAO,MAAMC,KAAK,GAAG;AAAEC,EAAAA,UAAU,EAAEH,eAAd;AAA+BI,EAAAA,OAAO,EAAEH;AAAxC,CAAd;AAEP,SAASJ,OAAT,QAAmC,qBAAnC,C,CAGA;;AACA,SAASQ,MAAT,QAAuB,2BAAvB","sourcesContent":["\nexport { DecodeError } from './schema/Schema';\nexport { resourceDef } from './loader/Resource.js';\n\nexport { default as createAgent } from './agent.js';\n\nexport { default as RestApi } from './loader/RestApi.js';\n\nimport reduxMiddleware from './redux/middleware.js';\nimport reduxReduce from './redux/reducer.js';\nexport const redux = { middleware: reduxMiddleware, reducer: reduxReduce };\n\nexport { default as default } from './loader/RestApi.js';\n\n\n// Re-export from lifecycle-loader, for convenience\nexport { status } from '@mkrause/lifecycle-loader';\n"],"file":"index.js"} |
| import $msg from 'message-tag'; | ||
| import { DecodeError } from '../schema/Schema.js'; | ||
| import * as t from 'io-ts'; | ||
| import * as t from 'io-ts'; //import { isLeft } from 'fp-ts/lib/Either'; | ||
| //import { Errors as ValidationErrors, ValidationError } from 'io-ts'; | ||
| import { PathReporter } from 'io-ts/lib/PathReporter.js'; | ||
@@ -5,0 +7,0 @@ |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../../src/loader/Adapter.ts"],"names":["$msg","DecodeError","t","PathReporter","makeAdapter","resource","schema","with","parse","response","status","data","decode","input","agent","adapter","report","encode","instance","decodeResult","_tag","right","errors","left","message","map","error","join","format","item","partial","props","getKey","id","TypeError"],"mappings":"AACA,OAAOA,IAAP,MAAiB,aAAjB;AAEA,SAAiBC,WAAjB,QAAoC,qBAApC;AAOA,OAAO,KAAKC,CAAZ,MAAmB,OAAnB;AA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;AACJ,GAnC+G;;AAqChHM,EAAAA,MAAM,CAACC,IAAD,EAAiB;AAAE,WAAOA,IAAP;AAAa,GArC0E;;AAuChHC,EAAAA,OAAO,GAAG;AACN,QAAI,WAAWxB,MAAf,EAAuB;AACnB,aAAOJ,CAAC,CAAC4B,OAAF,CAAWxB,MAAD,CAAgByB,KAA1B,CAAP;AACH,KAFD,MAEO;AACH,aAAOzB,MAAP;AACH;AACJ,GA7C+G;;AA+ChH0B,EAAAA,MAAM,CAACd,QAAD,EAA8B;AAChC,QAAI,OAAOA,QAAP,KAAoB,QAApB,IAAgCA,QAAQ,KAAK,IAA7C,IAAqD,QAAQA,QAAjE,EAA2E;AACvE,aAAQA,QAAD,CAA+Be,EAAtC;AACH;;AAED,UAAM,IAAIC,SAAJ,CAAclC,IAAK,yBAAwBkB,QAAS,EAApD,CAAN;AACH;AAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AA7EoH,CAAhG,CAApB,C,CAgFA;AACA;AACA;;;AAGA,eAAed,WAAf","sourcesContent":["\nimport $msg from 'message-tag';\n\nimport { Schema, DecodeError } from '../schema/Schema.js';\n\nimport type { Resource } from './Resource.js';\nimport { ResourceDefinition } from './Resource.js';\n\nimport { AxiosResponse } from 'axios';\n\nimport * as t from 'io-ts';\nimport { isLeft } from 'fp-ts/lib/Either';\nimport { Errors as ValidationErrors, ValidationError } from 'io-ts';\nimport { PathReporter } from 'io-ts/lib/PathReporter.js';\n\n\nconst makeAdapter = <S extends Schema<unknown>>(resource : ResourceDefinition<S>, schema : S = resource.schema) => ({\n with(schema : Schema) {\n return makeAdapter(resource, schema);\n },\n \n parse(response : AxiosResponse) {\n if (response.status === 204) { return null; }\n return response.data;\n },\n \n decode(input : unknown) {\n const { agent, adapter } = resource;\n \n return adapter.report(schema.decode(input));\n },\n \n encode(instance : unknown) {\n const { agent, adapter } = resource;\n \n return schema.encode(instance);\n },\n \n report(decodeResult : t.Validation<unknown>) {\n if (decodeResult._tag === 'Right') {\n return decodeResult.right;\n } else {\n const errors = decodeResult.left;\n const report = PathReporter.report(decodeResult);\n \n const message = `Failed to decode response:\\n` + report.map(error =>\n `\\n- ${error}`\n ).join('');\n \n throw new DecodeError(message, errors);\n }\n },\n \n format(item : unknown) { return item },\n \n partial() {\n if ('props' in schema) {\n return t.partial((schema as any).props);\n } else {\n return schema;\n }\n },\n \n getKey(instance : t.TypeOf<Schema>) {\n if (typeof instance === 'object' && instance !== null && 'id' in instance) {\n return (instance as { id : unknown }).id;\n }\n \n throw new TypeError($msg`Unable to get key for ${instance}`);\n },\n \n /* TODO\n keyOf() {\n // If the schema is `any`, try to find a default `id` property?\n if (schema.name === 'Unknown') { // TEMP\n const IdType = t.type({ id: t.any });\n return new Type(\n 'keyof ' + IdType.name,\n IdType.is,\n (input : t.InputOf<typeof IdType>, context : t.Context) => {\n const e = IdType.validate(input, context);\n if (isLeft(e)) {\n return e;\n }\n \n return e.right.id;\n },\n (instance : unknown) => instance,\n );\n }\n \n return schema\n },\n */\n});\n\n// Get the return type of `Adapter`\n// FIXME: currently this leads to a circular reference\n//export type AdapterT = typeof Adapter extends <S extends Schema>(...args : never[]) => infer R ? R : never;\nexport type AdapterT = any;\n\nexport default makeAdapter;\n"],"file":"Adapter.js"} | ||
| {"version":3,"sources":["../../src/loader/Adapter.ts"],"names":["$msg","DecodeError","t","PathReporter","makeAdapter","resource","schema","with","parse","response","status","data","decode","input","agent","adapter","report","encode","instance","decodeResult","_tag","right","errors","left","message","map","error","join","format","item","partial","props","getKey","id","TypeError"],"mappings":"AACA,OAAOA,IAAP,MAAiB,aAAjB;AAEA,SAAiBC,WAAjB,QAAoC,qBAApC;AAOA,OAAO,KAAKC,CAAZ,MAAmB,OAAnB,C,CACA;AACA;;AACA,SAASC,YAAT,QAA6B,2BAA7B;;AAGA,MAAMC,WAAW,GAAG,CAA4BC,QAA5B,EAA8DC,M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GArC0E;;AAuChHC,EAAAA,OAAO,GAAG;AACN,QAAI,WAAWxB,MAAf,EAAuB;AACnB,aAAOJ,CAAC,CAAC4B,OAAF,CAAWxB,MAAD,CAAgByB,KAA1B,CAAP;AACH,KAFD,MAEO;AACH,aAAOzB,MAAP;AACH;AACJ,GA7C+G;;AA+ChH0B,EAAAA,MAAM,CAACd,QAAD,EAA8B;AAChC,QAAI,OAAOA,QAAP,KAAoB,QAApB,IAAgCA,QAAQ,KAAK,IAA7C,IAAqD,QAAQA,QAAjE,EAA2E;AACvE,aAAQA,QAAD,CAA+Be,EAAtC;AACH;;AAED,UAAM,IAAIC,SAAJ,CAAclC,IAAK,yBAAwBkB,QAAS,EAApD,CAAN;AACH;AAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AA7EoH,CAAhG,CAApB,C,CAgFA;AACA;AACA;;;AAGA,eAAed,WAAf","sourcesContent":["\nimport $msg from 'message-tag';\n\nimport { Schema, DecodeError } from '../schema/Schema.js';\n\nimport type { Resource } from './Resource.js';\nimport { ResourceDefinition } from './Resource.js';\n\nimport { AxiosResponse } from 'axios';\n\nimport * as t from 'io-ts';\n//import { isLeft } from 'fp-ts/lib/Either';\n//import { Errors as ValidationErrors, ValidationError } from 'io-ts';\nimport { PathReporter } from 'io-ts/lib/PathReporter.js';\n\n\nconst makeAdapter = <S extends Schema<unknown>>(resource : ResourceDefinition<S>, schema : S = resource.schema) => ({\n with(schema : Schema) {\n return makeAdapter(resource, schema);\n },\n \n parse(response : AxiosResponse) {\n if (response.status === 204) { return null; }\n return response.data;\n },\n \n decode(input : unknown) {\n const { agent, adapter } = resource;\n \n return adapter.report(schema.decode(input));\n },\n \n encode(instance : unknown) {\n const { agent, adapter } = resource;\n \n return schema.encode(instance);\n },\n \n report(decodeResult : t.Validation<unknown>) {\n if (decodeResult._tag === 'Right') {\n return decodeResult.right;\n } else {\n const errors = decodeResult.left;\n const report = PathReporter.report(decodeResult);\n \n const message = `Failed to decode response:\\n` + report.map(error =>\n `\\n- ${error}`\n ).join('');\n \n throw new DecodeError(message, errors);\n }\n },\n \n format(item : unknown) { return item },\n \n partial() {\n if ('props' in schema) {\n return t.partial((schema as any).props);\n } else {\n return schema;\n }\n },\n \n getKey(instance : t.TypeOf<Schema>) {\n if (typeof instance === 'object' && instance !== null && 'id' in instance) {\n return (instance as { id : unknown }).id;\n }\n \n throw new TypeError($msg`Unable to get key for ${instance}`);\n },\n \n /* TODO\n keyOf() {\n // If the schema is `any`, try to find a default `id` property?\n if (schema.name === 'Unknown') { // TEMP\n const IdType = t.type({ id: t.any });\n return new Type(\n 'keyof ' + IdType.name,\n IdType.is,\n (input : t.InputOf<typeof IdType>, context : t.Context) => {\n const e = IdType.validate(input, context);\n if (isLeft(e)) {\n return e;\n }\n \n return e.right.id;\n },\n (instance : unknown) => instance,\n );\n }\n \n return schema\n },\n */\n});\n\n// Get the return type of `Adapter`\n// FIXME: currently this leads to a circular reference\n//export type AdapterT = typeof Adapter extends <S extends Schema>(...args : never[]) => infer R ? R : never;\nexport type AdapterT = any;\n\nexport default makeAdapter;\n"],"file":"Adapter.js"} |
+1
-1
| { | ||
| "name": "@mkrause/lifecycle-rest", | ||
| "version": "0.5.3", | ||
| "version": "0.5.4", | ||
| "author": "mkrause", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+1
-0
| export { DecodeError } from './schema/Schema'; | ||
| export { resourceDef } from './loader/Resource.js'; | ||
@@ -3,0 +4,0 @@ |
@@ -12,4 +12,4 @@ | ||
| import * as t from 'io-ts'; | ||
| import { isLeft } from 'fp-ts/lib/Either'; | ||
| import { Errors as ValidationErrors, ValidationError } from 'io-ts'; | ||
| //import { isLeft } from 'fp-ts/lib/Either'; | ||
| //import { Errors as ValidationErrors, ValidationError } from 'io-ts'; | ||
| import { PathReporter } from 'io-ts/lib/PathReporter.js'; | ||
@@ -16,0 +16,0 @@ |
@@ -0,1 +1,2 @@ | ||
| export { DecodeError } from './schema/Schema'; | ||
| export { resourceDef } from './loader/Resource.js'; | ||
@@ -5,7 +6,7 @@ export { default as createAgent } from './agent.js'; | ||
| export declare const redux: { | ||
| middleware: (configPartial?: Partial<import("./redux/middleware.js").Config>) => (store: import("redux").Store<any, import("redux").AnyAction>) => (next: import("redux").Dispatch<import("redux").AnyAction>) => <A extends import("redux").AnyAction, R>(action: A) => A | import("./loader/StorablePromise.js").StorablePromise<R>; | ||
| middleware: (configPartial?: Partial<import("./redux/middleware.js").Config>) => (store: import("redux").Store<any, import("redux").AnyAction>) => (next: import("redux").Dispatch<import("redux").AnyAction>) => <A extends import("redux").AnyAction, R>(action: A) => A | import("./loader/StorablePromise").StorablePromise<R>; | ||
| reducer: (configPartial?: Partial<{ | ||
| prefix: string; | ||
| trackRequests: boolean; | ||
| requestsPath: import("./loader/Location.js").Step[]; | ||
| requestsPath: import("./loader/Location").Step[]; | ||
| }>) => import("redux").Reducer<unknown, import("redux").AnyAction>; | ||
@@ -12,0 +13,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAIzD,eAAO,MAAM,KAAK;;;;;;;CAAwD,CAAC;AAE3E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAIzD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAIzD,eAAO,MAAM,KAAK;;;;;;;CAAwD,CAAC;AAE3E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAIzD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC"} |
456475
0.18%4538
0.29%