@vsaas/remoting 10.0.0

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.
Files changed (109) hide show
  1. package/LICENSE.md +202 -0
  2. package/README.md +78 -0
  3. package/dist/_virtual/_rolldown/runtime.js +32 -0
  4. package/dist/ext/meta.d.ts +1 -0
  5. package/dist/ext/meta.js +39 -0
  6. package/dist/ext/meta.js.map +1 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +20 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/lib/context-base.d.ts +1 -0
  11. package/dist/lib/context-base.js +30 -0
  12. package/dist/lib/context-base.js.map +1 -0
  13. package/dist/lib/deprecate.d.ts +1 -0
  14. package/dist/lib/deprecate.js +34 -0
  15. package/dist/lib/deprecate.js.map +1 -0
  16. package/dist/lib/escape-regexp.d.ts +1 -0
  17. package/dist/lib/escape-regexp.js +12 -0
  18. package/dist/lib/escape-regexp.js.map +1 -0
  19. package/dist/lib/exports-helper.d.ts +1 -0
  20. package/dist/lib/exports-helper.js +101 -0
  21. package/dist/lib/exports-helper.js.map +1 -0
  22. package/dist/lib/http-context.d.ts +1 -0
  23. package/dist/lib/http-context.js +484 -0
  24. package/dist/lib/http-context.js.map +1 -0
  25. package/dist/lib/http-invocation.d.ts +1 -0
  26. package/dist/lib/http-invocation.js +254 -0
  27. package/dist/lib/http-invocation.js.map +1 -0
  28. package/dist/lib/jsonrpc-adapter.d.ts +1 -0
  29. package/dist/lib/jsonrpc-adapter.js +187 -0
  30. package/dist/lib/jsonrpc-adapter.js.map +1 -0
  31. package/dist/lib/looks-like-json.d.ts +1 -0
  32. package/dist/lib/looks-like-json.js +22 -0
  33. package/dist/lib/looks-like-json.js.map +1 -0
  34. package/dist/lib/messages.d.ts +1 -0
  35. package/dist/lib/messages.js +24 -0
  36. package/dist/lib/messages.js.map +1 -0
  37. package/dist/lib/number-checks.d.ts +1 -0
  38. package/dist/lib/number-checks.js +18 -0
  39. package/dist/lib/number-checks.js.map +1 -0
  40. package/dist/lib/phases/merge-phase-name-lists.d.ts +5 -0
  41. package/dist/lib/phases/merge-phase-name-lists.d.ts.map +1 -0
  42. package/dist/lib/phases/merge-phase-name-lists.js +39 -0
  43. package/dist/lib/phases/merge-phase-name-lists.js.map +1 -0
  44. package/dist/lib/phases/phase-list.d.ts +27 -0
  45. package/dist/lib/phases/phase-list.d.ts.map +1 -0
  46. package/dist/lib/phases/phase-list.js +154 -0
  47. package/dist/lib/phases/phase-list.js.map +1 -0
  48. package/dist/lib/phases/phase.d.ts +24 -0
  49. package/dist/lib/phases/phase.d.ts.map +1 -0
  50. package/dist/lib/phases/phase.js +144 -0
  51. package/dist/lib/phases/phase.js.map +1 -0
  52. package/dist/lib/remote-objects.d.ts +1 -0
  53. package/dist/lib/remote-objects.js +642 -0
  54. package/dist/lib/remote-objects.js.map +1 -0
  55. package/dist/lib/rest-adapter-browser.d.ts +1 -0
  56. package/dist/lib/rest-adapter-browser.js +302 -0
  57. package/dist/lib/rest-adapter-browser.js.map +1 -0
  58. package/dist/lib/rest-adapter.d.ts +1 -0
  59. package/dist/lib/rest-adapter.js +519 -0
  60. package/dist/lib/rest-adapter.js.map +1 -0
  61. package/dist/lib/server-sent-events.d.ts +1 -0
  62. package/dist/lib/server-sent-events.js +61 -0
  63. package/dist/lib/server-sent-events.js.map +1 -0
  64. package/dist/lib/shared-class.d.ts +1 -0
  65. package/dist/lib/shared-class.js +207 -0
  66. package/dist/lib/shared-class.js.map +1 -0
  67. package/dist/lib/shared-method.d.ts +1 -0
  68. package/dist/lib/shared-method.js +469 -0
  69. package/dist/lib/shared-method.js.map +1 -0
  70. package/dist/lib/socket-io-adapter.d.ts +1 -0
  71. package/dist/lib/socket-io-adapter.js +93 -0
  72. package/dist/lib/socket-io-adapter.js.map +1 -0
  73. package/dist/lib/socket-io-context.d.ts +1 -0
  74. package/dist/lib/socket-io-context.js +94 -0
  75. package/dist/lib/socket-io-context.js.map +1 -0
  76. package/dist/lib/type-registry.d.ts +1 -0
  77. package/dist/lib/type-registry.js +99 -0
  78. package/dist/lib/type-registry.js.map +1 -0
  79. package/dist/lib/types/any.d.ts +1 -0
  80. package/dist/lib/types/any.js +44 -0
  81. package/dist/lib/types/any.js.map +1 -0
  82. package/dist/lib/types/array.d.ts +1 -0
  83. package/dist/lib/types/array.js +99 -0
  84. package/dist/lib/types/array.js.map +1 -0
  85. package/dist/lib/types/boolean.d.ts +1 -0
  86. package/dist/lib/types/boolean.js +37 -0
  87. package/dist/lib/types/boolean.js.map +1 -0
  88. package/dist/lib/types/date.d.ts +1 -0
  89. package/dist/lib/types/date.js +37 -0
  90. package/dist/lib/types/date.js.map +1 -0
  91. package/dist/lib/types/geopoint.d.ts +1 -0
  92. package/dist/lib/types/geopoint.js +68 -0
  93. package/dist/lib/types/geopoint.js.map +1 -0
  94. package/dist/lib/types/integer.d.ts +1 -0
  95. package/dist/lib/types/integer.js +36 -0
  96. package/dist/lib/types/integer.js.map +1 -0
  97. package/dist/lib/types/number.d.ts +1 -0
  98. package/dist/lib/types/number.js +30 -0
  99. package/dist/lib/types/number.js.map +1 -0
  100. package/dist/lib/types/object.d.ts +1 -0
  101. package/dist/lib/types/object.js +57 -0
  102. package/dist/lib/types/object.js.map +1 -0
  103. package/dist/lib/types/string.d.ts +1 -0
  104. package/dist/lib/types/string.js +29 -0
  105. package/dist/lib/types/string.js.map +1 -0
  106. package/dist/phases.d.ts +4 -0
  107. package/dist/phases.js +35 -0
  108. package/dist/phases.js.map +1 -0
  109. package/package.json +96 -0
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.js");
3
+ require("./messages.js");
4
+ //#region src/lib/socket-io-context.ts
5
+ var require_socket_io_context = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
6
+ /**
7
+ * Expose `SocketIOContext`.
8
+ */
9
+ module.exports = SocketIOContext;
10
+ /**
11
+ * Module dependencies.
12
+ */
13
+ const EventEmitter = require("events").EventEmitter;
14
+ require("debug")("strong-remoting:socket-io-context");
15
+ const inherits = require("util").inherits;
16
+ require("assert");
17
+ /**
18
+ * Create a new `SocketIOContext` with the given `options`.
19
+ *
20
+ * @param {Object} options
21
+ * @return {SocketIOContext}
22
+ */
23
+ function SocketIOContext(req, ctorArgs, args) {
24
+ this.req = req;
25
+ this.ctorArgs = ctorArgs;
26
+ this.args = args;
27
+ }
28
+ /**
29
+ * Inherit from `EventEmitter`.
30
+ */
31
+ inherits(SocketIOContext, EventEmitter);
32
+ /**
33
+ * Get an arg by name using the given options.
34
+ *
35
+ * @param {String} name
36
+ * @param {Object} options **optional**
37
+ */
38
+ SocketIOContext.prototype.getArgByName = function(name, options) {
39
+ return this.args[name];
40
+ };
41
+ /**
42
+ * Set an arg by name using the given options.
43
+ *
44
+ * @param {String} name
45
+ * @param {Object} options **optional**
46
+ */
47
+ SocketIOContext.prototype.setArgByName = function(name, options) {
48
+ throw "not implemented";
49
+ };
50
+ /**
51
+ * Set part or all of the result by name using the given options.
52
+ *
53
+ * @param {String} name
54
+ * @param {Object} options **optional**
55
+ */
56
+ SocketIOContext.prototype.setResultByName = function(name, options) {};
57
+ /**
58
+ * Get part or all of the result by name using the given options.
59
+ *
60
+ * @param {String} name
61
+ * @param {Object} options **optional**
62
+ */
63
+ SocketIOContext.prototype.getResultByName = function(name, options) {};
64
+ /**
65
+ * Invoke the given shared method using the provided scope against
66
+ * the current context.
67
+ */
68
+ SocketIOContext.prototype.invoke = function(scope, method, fn) {
69
+ const args = method.isSharedCtor ? this.ctorArgs : this.args;
70
+ method.accepts;
71
+ const returns = method.returns;
72
+ method.errors;
73
+ let result;
74
+ method.invoke(scope, args, function(err) {
75
+ const resultArgs = arguments;
76
+ if (method.name === "on" && method.ctor instanceof EventEmitter) {
77
+ resultArgs[1] = resultArgs[0];
78
+ err = null;
79
+ }
80
+ if (err) return fn(err);
81
+ if (returns.length > 1) {
82
+ result = {};
83
+ returns.forEach(function(o, i) {
84
+ result[o.name || o.arg] = resultArgs[i + 1];
85
+ });
86
+ } else result = resultArgs[1];
87
+ fn(null, result);
88
+ });
89
+ };
90
+ }));
91
+ //#endregion
92
+ module.exports = require_socket_io_context();
93
+
94
+ //# sourceMappingURL=socket-io-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-io-context.js","names":[],"sources":["../../src/lib/socket-io-context.ts"],"sourcesContent":["// Copyright IBM Corp. 2013,2017. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\nconst g = require('./messages');\n/**\n * Expose `SocketIOContext`.\n */\nmodule.exports = SocketIOContext;\n\n/**\n * Module dependencies.\n */\n\nconst EventEmitter = require('events').EventEmitter;\nconst debug = require('debug')('strong-remoting:socket-io-context');\nconst util = require('util');\nconst inherits = util.inherits;\nconst assert = require('assert');\n\n/**\n * Create a new `SocketIOContext` with the given `options`.\n *\n * @param {Object} options\n * @return {SocketIOContext}\n */\n\nfunction SocketIOContext(req, ctorArgs, args) {\n this.req = req;\n this.ctorArgs = ctorArgs;\n this.args = args;\n}\n\n/**\n * Inherit from `EventEmitter`.\n */\n\ninherits(SocketIOContext, EventEmitter);\n\n/**\n * Get an arg by name using the given options.\n *\n * @param {String} name\n * @param {Object} options **optional**\n */\n\nSocketIOContext.prototype.getArgByName = function (name, options) {\n return this.args[name];\n};\n\n/**\n * Set an arg by name using the given options.\n *\n * @param {String} name\n * @param {Object} options **optional**\n */\n\nSocketIOContext.prototype.setArgByName = function (name, options) {\n throw 'not implemented';\n};\n\n/**\n * Set part or all of the result by name using the given options.\n *\n * @param {String} name\n * @param {Object} options **optional**\n */\n\nSocketIOContext.prototype.setResultByName = function (name, options) {};\n\n/**\n * Get part or all of the result by name using the given options.\n *\n * @param {String} name\n * @param {Object} options **optional**\n */\n\nSocketIOContext.prototype.getResultByName = function (name, options) {};\n\n/**\n * Invoke the given shared method using the provided scope against\n * the current context.\n */\n\nSocketIOContext.prototype.invoke = function (scope, method, fn) {\n const args = method.isSharedCtor ? this.ctorArgs : this.args;\n const accepts = method.accepts;\n const returns = method.returns;\n const errors = method.errors;\n let result;\n\n // invoke the shared method\n method.invoke(scope, args, function (err) {\n const resultArgs = arguments;\n\n if (method.name === 'on' && method.ctor instanceof EventEmitter) {\n resultArgs[1] = resultArgs[0];\n err = null;\n }\n\n if (err) {\n return fn(err);\n }\n\n // map the arguments using the returns description\n if (returns.length > 1) {\n // multiple\n result = {};\n\n returns.forEach(function (o, i) {\n // map the name of the arg in the returns desc\n // to the same arg in the callback\n result[o.name || o.arg] = resultArgs[i + 1];\n });\n } else {\n // single or no result...\n result = resultArgs[1];\n }\n\n fn(null, result);\n });\n};\n"],"mappings":";;;;;;;;AAYA,QAAO,UAAU;;;;CAMjB,MAAM,eAAe,QAAQ,SAAS,CAAC;AACzB,SAAQ,QAAQ,CAAC,oCAAoC;CAEnE,MAAM,WADO,QAAQ,OAAO,CACN;AACP,SAAQ,SAAS;;;;;;;CAShC,SAAS,gBAAgB,KAAK,UAAU,MAAM;AAC5C,OAAK,MAAM;AACX,OAAK,WAAW;AAChB,OAAK,OAAO;;;;;AAOd,UAAS,iBAAiB,aAAa;;;;;;;AASvC,iBAAgB,UAAU,eAAe,SAAU,MAAM,SAAS;AAChE,SAAO,KAAK,KAAK;;;;;;;;AAUnB,iBAAgB,UAAU,eAAe,SAAU,MAAM,SAAS;AAChE,QAAM;;;;;;;;AAUR,iBAAgB,UAAU,kBAAkB,SAAU,MAAM,SAAS;;;;;;;AASrE,iBAAgB,UAAU,kBAAkB,SAAU,MAAM,SAAS;;;;;AAOrE,iBAAgB,UAAU,SAAS,SAAU,OAAO,QAAQ,IAAI;EAC9D,MAAM,OAAO,OAAO,eAAe,KAAK,WAAW,KAAK;AACxC,SAAO;EACvB,MAAM,UAAU,OAAO;AACR,SAAO;EACtB,IAAI;AAGJ,SAAO,OAAO,OAAO,MAAM,SAAU,KAAK;GACxC,MAAM,aAAa;AAEnB,OAAI,OAAO,SAAS,QAAQ,OAAO,gBAAgB,cAAc;AAC/D,eAAW,KAAK,WAAW;AAC3B,UAAM;;AAGR,OAAI,IACF,QAAO,GAAG,IAAI;AAIhB,OAAI,QAAQ,SAAS,GAAG;AAEtB,aAAS,EAAE;AAEX,YAAQ,QAAQ,SAAU,GAAG,GAAG;AAG9B,YAAO,EAAE,QAAQ,EAAE,OAAO,WAAW,IAAI;MACzC;SAGF,UAAS,WAAW;AAGtB,MAAG,MAAM,OAAO;IAChB"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.js");
3
+ const require_lib_messages = require("./messages.js");
4
+ const require_lib_types_array = require("./types/array.js");
5
+ const require_lib_types_any = require("./types/any.js");
6
+ const require_lib_types_boolean = require("./types/boolean.js");
7
+ const require_lib_types_date = require("./types/date.js");
8
+ const require_lib_types_number = require("./types/number.js");
9
+ const require_lib_types_integer = require("./types/integer.js");
10
+ const require_lib_types_object = require("./types/object.js");
11
+ const require_lib_types_string = require("./types/string.js");
12
+ const require_lib_types_geopoint = require("./types/geopoint.js");
13
+ //#region src/lib/type-registry.ts
14
+ var require_type_registry = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
15
+ const ArrayConverter = require_lib_types_array;
16
+ const assert = require("assert");
17
+ const debug = require("debug")("strong-remoting:types");
18
+ const g = require_lib_messages;
19
+ module.exports = TypeRegistry;
20
+ function TypeRegistry(options) {
21
+ this._options = options || {};
22
+ this._arrayConverters = /* @__PURE__ */ new Map();
23
+ this._types = Object.create(null);
24
+ this._registerBuiltinTypes();
25
+ }
26
+ TypeRegistry.prototype.registerType = function(typeName, converter) {
27
+ assert(typeof typeName === "string" && typeName, "typeName must be a non-empty string");
28
+ assert(typeof converter === "object" && converter, "converter must be an object");
29
+ assert(typeof converter.fromTypedValue === "function", "converter.fromTypedValue must be a function");
30
+ assert(typeof converter.fromSloppyValue === "function", "converter.fromSloppyValue must be a function");
31
+ assert(typeof converter.validate === "function", "converter.validate must be a function");
32
+ typeName = typeName.toLowerCase();
33
+ if (typeName === "file") throw new Error(g.f("Cannot override built-in \"{{file}}\" type."));
34
+ if (typeName in this._types) if (this._options.warnWhenOverridingType !== false) g.warn("Warning: overriding remoting type %s", typeName);
35
+ else debug("Warning: overriding remoting type %s", typeName);
36
+ this._types[typeName] = converter;
37
+ };
38
+ TypeRegistry.prototype.registerObjectType = function(typeName, factoryFn) {
39
+ assert(typeof typeName === "string" && typeName, "typeName must be a non-empty string");
40
+ assert(typeof factoryFn === "function", "factoryFn must be a function");
41
+ this.registerType(typeName, {
42
+ fromTypedValue: function(ctx, data, options) {
43
+ const result = ctx.typeRegistry.getConverter("object").fromTypedValue(ctx, data, options);
44
+ if (result.error || result.value === void 0 || result.value === null) return result;
45
+ try {
46
+ return { value: factoryFn(result.value) };
47
+ } catch (err) {
48
+ return { error: err };
49
+ }
50
+ },
51
+ fromSloppyValue: function(ctx, value, options) {
52
+ const result = ctx.typeRegistry.getConverter("object").fromSloppyValue(ctx, value, options);
53
+ return result.error ? result : this.fromTypedValue(ctx, result.value);
54
+ },
55
+ validate: function(ctx, value, options) {
56
+ return ctx.typeRegistry.getConverter("object").validate(ctx, value, options);
57
+ }
58
+ });
59
+ };
60
+ TypeRegistry.prototype.getConverter = function(type) {
61
+ if (typeof type === "object" && Object.getPrototypeOf(type) === Object.prototype) {
62
+ debug("Treating inline object definition as a free-form object:", type);
63
+ type = "object";
64
+ }
65
+ assert(typeof type === "string" || Array.isArray(type), "\"type\" must be an array, a string or an object (an inline definition).");
66
+ if (type === "array") type = ["any"];
67
+ if (Array.isArray(type)) {
68
+ if (type.length !== 1) g.warn("Array types with more than one item type are not supported. Using the first item type and ignoring the rest.");
69
+ const itemType = type[0] || "any";
70
+ let arrayConverter = this._arrayConverters.get(itemType);
71
+ if (!arrayConverter) {
72
+ arrayConverter = new ArrayConverter(itemType);
73
+ this._arrayConverters.set(itemType, arrayConverter);
74
+ }
75
+ return arrayConverter;
76
+ }
77
+ type = type.toLowerCase();
78
+ return this._types[type] || this._getUnknownTypeConverter(type);
79
+ };
80
+ TypeRegistry.prototype._registerBuiltinTypes = function() {
81
+ this.registerType("any", require_lib_types_any);
82
+ this.registerType("boolean", require_lib_types_boolean);
83
+ this.registerType("date", require_lib_types_date);
84
+ this.registerType("integer", require_lib_types_integer);
85
+ this.registerType("number", require_lib_types_number);
86
+ this.registerType("object", require_lib_types_object);
87
+ this.registerType("string", require_lib_types_string);
88
+ this.registerType("geopoint", require_lib_types_geopoint);
89
+ };
90
+ TypeRegistry.prototype._getUnknownTypeConverter = function(type) {
91
+ if (this._options.warnOnUnknownType !== false) g.warn("Treating unknown remoting type %j as \"any\"", type);
92
+ else debug("Treating unknown remoting type %j as \"any\"", type);
93
+ return this.getConverter("any");
94
+ };
95
+ }));
96
+ //#endregion
97
+ module.exports = require_type_registry();
98
+
99
+ //# sourceMappingURL=type-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-registry.js","names":[],"sources":["../../src/lib/type-registry.ts"],"sourcesContent":["// Copyright IBM Corp. 2016,2017. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\nconst ArrayConverter = require('./types/array');\nconst assert = require('assert');\nconst debug = require('debug')('strong-remoting:types');\nconst g = require('./messages');\n\nmodule.exports = TypeRegistry;\n\nfunction TypeRegistry(options) {\n this._options = options || {};\n this._arrayConverters = new Map();\n this._types = Object.create(null);\n this._registerBuiltinTypes();\n}\n\nTypeRegistry.prototype.registerType = function (typeName, converter) {\n assert(typeof typeName === 'string' && typeName, 'typeName must be a non-empty string');\n assert(typeof converter === 'object' && converter, 'converter must be an object');\n assert(\n typeof converter.fromTypedValue === 'function',\n 'converter.fromTypedValue must be a function',\n );\n assert(\n typeof converter.fromSloppyValue === 'function',\n 'converter.fromSloppyValue must be a function',\n );\n assert(typeof converter.validate === 'function', 'converter.validate must be a function');\n\n typeName = typeName.toLowerCase();\n\n if (typeName === 'file') {\n throw new Error(g.f('Cannot override built-in \"{{file}}\" type.'));\n }\n\n if (typeName in this._types) {\n if (this._options.warnWhenOverridingType !== false)\n g.warn('Warning: overriding remoting type %s', typeName);\n else debug('Warning: overriding remoting type %s', typeName);\n }\n\n this._types[typeName] = converter;\n};\n\nTypeRegistry.prototype.registerObjectType = function (typeName, factoryFn) {\n assert(typeof typeName === 'string' && typeName, 'typeName must be a non-empty string');\n assert(typeof factoryFn === 'function', 'factoryFn must be a function');\n\n const converter = {\n fromTypedValue: function (ctx, data, options) {\n const objectConverter = ctx.typeRegistry.getConverter('object');\n const result = objectConverter.fromTypedValue(ctx, data, options);\n if (result.error || result.value === undefined || result.value === null) return result;\n\n try {\n return { value: factoryFn(result.value) };\n } catch (err) {\n return { error: err };\n }\n },\n\n fromSloppyValue: function (ctx, value, options) {\n const objectConverter = ctx.typeRegistry.getConverter('object');\n const result = objectConverter.fromSloppyValue(ctx, value, options);\n return result.error ? result : this.fromTypedValue(ctx, result.value);\n },\n\n validate: function (ctx, value, options) {\n return ctx.typeRegistry.getConverter('object').validate(ctx, value, options);\n },\n };\n\n this.registerType(typeName, converter);\n};\n\nTypeRegistry.prototype.getConverter = function (type) {\n const isAnonynousObjectTypeDefinition =\n typeof type === 'object' && Object.getPrototypeOf(type) === Object.prototype;\n\n if (isAnonynousObjectTypeDefinition) {\n debug('Treating inline object definition as a free-form object:', type);\n type = 'object';\n }\n\n assert(\n typeof type === 'string' || Array.isArray(type),\n '\"type\" must be an array, a string or an object (an inline definition).',\n );\n\n if (type === 'array') type = ['any'];\n\n if (Array.isArray(type)) {\n if (type.length !== 1) {\n g.warn(\n 'Array types with more than one item type are not supported. ' +\n 'Using the first item type and ignoring the rest.',\n );\n }\n\n const itemType = type[0] || 'any';\n let arrayConverter = this._arrayConverters.get(itemType);\n if (!arrayConverter) {\n arrayConverter = new ArrayConverter(itemType);\n this._arrayConverters.set(itemType, arrayConverter);\n }\n\n return arrayConverter;\n }\n\n type = type.toLowerCase();\n\n // TODO fall-back to Dynamic converters\n return this._types[type] || this._getUnknownTypeConverter(type);\n};\n\nTypeRegistry.prototype._registerBuiltinTypes = function () {\n // NOTE we have to explicitly enumerate all scripts to support browserify\n this.registerType('any', require('./types/any'));\n this.registerType('boolean', require('./types/boolean'));\n this.registerType('date', require('./types/date'));\n this.registerType('integer', require('./types/integer'));\n this.registerType('number', require('./types/number'));\n this.registerType('object', require('./types/object'));\n this.registerType('string', require('./types/string'));\n this.registerType('geopoint', require('./types/geopoint'));\n};\n\nTypeRegistry.prototype._getUnknownTypeConverter = function (type) {\n if (this._options.warnOnUnknownType !== false)\n g.warn('Treating unknown remoting type %j as \"any\"', type);\n else debug('Treating unknown remoting type %j as \"any\"', type);\n\n return this.getConverter('any');\n};\n"],"mappings":"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"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ const require_runtime = require("../../_virtual/_rolldown/runtime.js");
3
+ require("../messages.js");
4
+ const require_lib_looks_like_json = require("../looks-like-json.js");
5
+ const require_lib_number_checks = require("../number-checks.js");
6
+ //#region src/lib/types/any.ts
7
+ var require_any = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
8
+ const debug = require("debug")("strong-remoting:http-coercion");
9
+ const numberChecks = require_lib_number_checks;
10
+ const looksLikeJson = require_lib_looks_like_json.looksLikeJson;
11
+ const MAX_SAFE_INTEGER = numberChecks.MAX_SAFE_INTEGER;
12
+ const MIN_SAFE_INTEGER = numberChecks.MIN_SAFE_INTEGER;
13
+ const IS_INT_REGEX = /^\-?(?:[0-9]|[1-9][0-9]*)$/;
14
+ const IS_FLOAT_REGEX = /^\-?([0-9]+)?\.[0-9]+$/;
15
+ module.exports = {
16
+ fromTypedValue: function(ctx, value, options) {
17
+ return { value };
18
+ },
19
+ fromSloppyValue: function(ctx, value, options) {
20
+ if (value === "null" || value === null) return { value: null };
21
+ if (typeof value !== "string") return { value };
22
+ if (value === "") return { value: void 0 };
23
+ if (value.toLowerCase() === "true") return { value: true };
24
+ if (value.toLowerCase() === "false") return { value: false };
25
+ if (IS_FLOAT_REGEX.test(value) || IS_INT_REGEX.test(value)) {
26
+ const num = +value;
27
+ if (MIN_SAFE_INTEGER <= num && num <= MAX_SAFE_INTEGER) value = num;
28
+ }
29
+ if (looksLikeJson(value)) try {
30
+ const result = JSON.parse(value);
31
+ debug("parsed %j as JSON: %j", value, result);
32
+ return this.fromTypedValue(ctx, result, options);
33
+ } catch (ex) {
34
+ debug("Cannot parse \"any\" value %j, assuming string. %s", value, ex);
35
+ }
36
+ return this.fromTypedValue(ctx, value, options);
37
+ },
38
+ validate: function(ctx, value, options) {}
39
+ };
40
+ }));
41
+ //#endregion
42
+ module.exports = require_any();
43
+
44
+ //# sourceMappingURL=any.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"any.js","names":[],"sources":["../../../src/lib/types/any.ts"],"sourcesContent":["// Copyright IBM Corp. 2016,2017. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\nconst debug = require('debug')('strong-remoting:http-coercion');\nconst g = require('../messages');\nconst numberChecks = require('../number-checks');\nconst looksLikeJson = require('../looks-like-json').looksLikeJson;\n\nconst MAX_SAFE_INTEGER = numberChecks.MAX_SAFE_INTEGER;\nconst MIN_SAFE_INTEGER = numberChecks.MIN_SAFE_INTEGER;\n\nconst IS_INT_REGEX = /^\\-?(?:[0-9]|[1-9][0-9]*)$/;\nconst IS_FLOAT_REGEX = /^\\-?([0-9]+)?\\.[0-9]+$/;\n\nmodule.exports = {\n fromTypedValue: function (ctx, value, options) {\n return { value: value };\n },\n\n fromSloppyValue: function (ctx, value, options) {\n if (value === 'null' || value === null) return { value: null };\n\n if (typeof value !== 'string') return { value: value };\n\n if (value === '') {\n // Pass on empty string as undefined.\n // undefined was chosen so that it plays well with ES6 default parameters.\n return { value: undefined };\n }\n\n if (value.toLowerCase() === 'true') return { value: true };\n\n if (value.toLowerCase() === 'false') return { value: false };\n\n if (IS_FLOAT_REGEX.test(value) || IS_INT_REGEX.test(value)) {\n const num = +value;\n // Cap at MAX_SAFE_INTEGER so we don't lose precision.\n if (MIN_SAFE_INTEGER <= num && num <= MAX_SAFE_INTEGER) value = num;\n }\n\n if (looksLikeJson(value)) {\n try {\n const result = JSON.parse(value);\n debug('parsed %j as JSON: %j', value, result);\n return this.fromTypedValue(ctx, result, options);\n } catch (ex) {\n debug('Cannot parse \"any\" value %j, assuming string. %s', value, ex);\n // no-op, use the original string value\n }\n }\n\n return this.fromTypedValue(ctx, value, options);\n },\n\n validate: function (ctx, value, options) {\n // no-op, all values are valid\n },\n};\n"],"mappings":";;;;;;;CAQA,MAAM,QAAQ,QAAQ,QAAQ,CAAC,gCAAgC;CAE/D,MAAM,eAAA;CACN,MAAM,gBAAA,4BAA8C;CAEpD,MAAM,mBAAmB,aAAa;CACtC,MAAM,mBAAmB,aAAa;CAEtC,MAAM,eAAe;CACrB,MAAM,iBAAiB;AAEvB,QAAO,UAAU;EACf,gBAAgB,SAAU,KAAK,OAAO,SAAS;AAC7C,UAAO,EAAS,OAAO;;EAGzB,iBAAiB,SAAU,KAAK,OAAO,SAAS;AAC9C,OAAI,UAAU,UAAU,UAAU,KAAM,QAAO,EAAE,OAAO,MAAM;AAE9D,OAAI,OAAO,UAAU,SAAU,QAAO,EAAS,OAAO;AAEtD,OAAI,UAAU,GAGZ,QAAO,EAAE,OAAO,KAAA,GAAW;AAG7B,OAAI,MAAM,aAAa,KAAK,OAAQ,QAAO,EAAE,OAAO,MAAM;AAE1D,OAAI,MAAM,aAAa,KAAK,QAAS,QAAO,EAAE,OAAO,OAAO;AAE5D,OAAI,eAAe,KAAK,MAAM,IAAI,aAAa,KAAK,MAAM,EAAE;IAC1D,MAAM,MAAM,CAAC;AAEb,QAAI,oBAAoB,OAAO,OAAO,iBAAkB,SAAQ;;AAGlE,OAAI,cAAc,MAAM,CACtB,KAAI;IACF,MAAM,SAAS,KAAK,MAAM,MAAM;AAChC,UAAM,yBAAyB,OAAO,OAAO;AAC7C,WAAO,KAAK,eAAe,KAAK,QAAQ,QAAQ;YACzC,IAAI;AACX,UAAM,sDAAoD,OAAO,GAAG;;AAKxE,UAAO,KAAK,eAAe,KAAK,OAAO,QAAQ;;EAGjD,UAAU,SAAU,KAAK,OAAO,SAAS;EAG1C"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ const require_runtime = require("../../_virtual/_rolldown/runtime.js");
3
+ const require_lib_messages = require("../messages.js");
4
+ const require_lib_escape_regexp = require("../escape-regexp.js");
5
+ const require_lib_looks_like_json = require("../looks-like-json.js");
6
+ //#region src/lib/types/array.ts
7
+ var require_array = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
8
+ const assert = require("assert");
9
+ const debug = require("debug")("strong-remoting:http-coercion");
10
+ const escapeRegex = require_lib_escape_regexp;
11
+ const g = require_lib_messages;
12
+ const looksLikeJsonArray = require_lib_looks_like_json.looksLikeJsonArray;
13
+ module.exports = ArrayConverter;
14
+ function ArrayConverter(itemType) {
15
+ this._itemType = itemType;
16
+ }
17
+ ArrayConverter.prototype.fromTypedValue = function(ctx, value, options) {
18
+ if (value === void 0 || value === null) return { value };
19
+ if (!Array.isArray(value)) return { error: notAnArrayError() };
20
+ const items = new Array(value.length);
21
+ let itemResult;
22
+ const itemConverter = ctx.typeRegistry.getConverter(this._itemType);
23
+ for (const ix in value) {
24
+ itemResult = itemConverter.fromTypedValue(ctx, value[ix], options);
25
+ itemResult = validateConverterResult(itemResult);
26
+ debug("typed item result: %j -> %j as %s", value[ix], itemResult, this._itemType);
27
+ if (itemResult.error) return itemResult;
28
+ items[ix] = itemResult.value;
29
+ }
30
+ return { value: items };
31
+ };
32
+ ArrayConverter.prototype.fromSloppyValue = function(ctx, value, options) {
33
+ if (value === void 0 || value === "") return { value: void 0 };
34
+ if (value === null || value === "null") return { value: null };
35
+ return this._fromTypedValueString(ctx, value, options) || this._fromDelimitedString(ctx, value, options) || this._fromSloppyData(ctx, value, options);
36
+ };
37
+ ArrayConverter.prototype._fromTypedValueString = function(ctx, value, options) {
38
+ if (!looksLikeJsonArray(value)) return null;
39
+ try {
40
+ const result = JSON.parse(value);
41
+ debug("parsed %j as JSON: %j", value, result);
42
+ return this.fromTypedValue(ctx, result, options);
43
+ } catch (ex) {
44
+ debug("Cannot parse array value %j. %s", value, ex);
45
+ const err = new Error(g.f("Cannot parse JSON-encoded array value."));
46
+ err.statusCode = 400;
47
+ return { error: err };
48
+ }
49
+ };
50
+ ArrayConverter.prototype._fromDelimitedString = function(ctx, value, options) {
51
+ if (typeof value !== "string") return null;
52
+ let delims = ctx.options && ctx.options.arrayItemDelimiters;
53
+ if (!delims) return null;
54
+ if (Array.isArray(delims)) {
55
+ delims = new RegExp(delims.map(escapeRegex).join("|"), "g");
56
+ ctx.options.arrayItemDelimiters = delims;
57
+ }
58
+ const items = value.split(delims);
59
+ return this.fromSloppyValue(ctx, items, options);
60
+ };
61
+ ArrayConverter.prototype._fromSloppyData = function(ctx, value, options) {
62
+ if (!Array.isArray(value)) value = [value];
63
+ debug("Intermediate sloppy array result: %j", value);
64
+ const items = new Array(value.length);
65
+ let itemResult;
66
+ const itemConverter = ctx.typeRegistry.getConverter(this._itemType);
67
+ for (const ix in value) {
68
+ itemResult = itemConverter.fromSloppyValue(ctx, value[ix], options);
69
+ itemResult = validateConverterResult(itemResult);
70
+ debug("item %d: sloppy converted %j to %j", ix, value[ix], itemResult);
71
+ if (itemResult.error) return itemResult;
72
+ items[ix] = itemResult.value;
73
+ }
74
+ return { value: items };
75
+ };
76
+ ArrayConverter.prototype.validate = function(ctx, value, options) {
77
+ if (value === void 0 || value === null) return null;
78
+ if (!Array.isArray(value)) return notAnArrayError();
79
+ const itemConverter = ctx.typeRegistry.getConverter(this._itemType);
80
+ let itemError;
81
+ for (const ix in value) {
82
+ itemError = itemConverter.validate(ctx, value[ix], options);
83
+ if (itemError) return itemError;
84
+ }
85
+ };
86
+ function notAnArrayError() {
87
+ const err = new Error(g.f("Value is not an array."));
88
+ err.statusCode = 400;
89
+ return err;
90
+ }
91
+ function validateConverterResult(result) {
92
+ if (typeof result === "object" && ("error" in result || "value" in result)) return result;
93
+ return { error: new assert.AssertionError({ message: "Type conversion result should have \"error\" or \"value\" property. Got " + JSON.stringify(result) + " instead." }) };
94
+ }
95
+ }));
96
+ //#endregion
97
+ module.exports = require_array();
98
+
99
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","names":[],"sources":["../../../src/lib/types/array.ts"],"sourcesContent":["// Copyright IBM Corp. 2016,2017. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\nconst assert = require('assert');\nconst debug = require('debug')('strong-remoting:http-coercion');\nconst escapeRegex = require('../escape-regexp');\nconst g = require('../messages');\nconst looksLikeJsonArray = require('../looks-like-json').looksLikeJsonArray;\n\nmodule.exports = ArrayConverter;\n\nfunction ArrayConverter(itemType) {\n this._itemType = itemType;\n}\n\nArrayConverter.prototype.fromTypedValue = function (ctx, value, options) {\n if (value === undefined || value === null) return { value: value };\n\n if (!Array.isArray(value)) return { error: notAnArrayError() };\n\n const items = new Array(value.length);\n let itemResult;\n const itemConverter = ctx.typeRegistry.getConverter(this._itemType);\n\n for (const ix in value) {\n itemResult = itemConverter.fromTypedValue(ctx, value[ix], options);\n itemResult = validateConverterResult(itemResult);\n debug('typed item result: %j -> %j as %s', value[ix], itemResult, this._itemType);\n\n if (itemResult.error) return itemResult;\n items[ix] = itemResult.value;\n }\n return { value: items };\n};\n\nArrayConverter.prototype.fromSloppyValue = function (ctx, value, options) {\n if (value === undefined || value === '') {\n // undefined was chosen so that it plays well with ES6 default parameters.\n return { value: undefined };\n }\n\n if (value === null || value === 'null') {\n return { value: null };\n }\n\n return (\n this._fromTypedValueString(ctx, value, options) ||\n this._fromDelimitedString(ctx, value, options) ||\n this._fromSloppyData(ctx, value, options)\n );\n};\n\nArrayConverter.prototype._fromTypedValueString = function (ctx, value, options) {\n if (!looksLikeJsonArray(value)) return null;\n\n // If it looks like a JSON array, try to parse it.\n try {\n const result = JSON.parse(value);\n debug('parsed %j as JSON: %j', value, result);\n return this.fromTypedValue(ctx, result, options);\n } catch (ex) {\n debug('Cannot parse array value %j. %s', value, ex);\n const err = new Error(g.f('Cannot parse JSON-encoded array value.'));\n err.statusCode = 400;\n return { error: err };\n }\n};\n\nArrayConverter.prototype._fromDelimitedString = function (ctx, value, options) {\n if (typeof value !== 'string') return null;\n\n // The user may set delimiters like ',', or ';' to designate array items\n // for easier usage.\n let delims = ctx.options && ctx.options.arrayItemDelimiters;\n if (!delims) return null;\n\n // Construct delimiter regex if input was an array. Overwrite option\n // so this only needs to happen once.\n if (Array.isArray(delims)) {\n delims = new RegExp(delims.map(escapeRegex).join('|'), 'g');\n ctx.options.arrayItemDelimiters = delims;\n }\n\n const items = value.split(delims);\n\n // perform sloppy-string coercion\n return this.fromSloppyValue(ctx, items, options);\n};\n\nArrayConverter.prototype._fromSloppyData = function (ctx, value, options) {\n if (!Array.isArray(value)) {\n // Alright, not array-like, just wrap it in an array on the way out.\n value = [value];\n }\n\n debug('Intermediate sloppy array result: %j', value);\n\n const items = new Array(value.length);\n let itemResult;\n const itemConverter = ctx.typeRegistry.getConverter(this._itemType);\n\n for (const ix in value) {\n itemResult = itemConverter.fromSloppyValue(ctx, value[ix], options);\n itemResult = validateConverterResult(itemResult);\n debug('item %d: sloppy converted %j to %j', ix, value[ix], itemResult);\n if (itemResult.error) return itemResult;\n items[ix] = itemResult.value;\n }\n return { value: items };\n};\n\nArrayConverter.prototype.validate = function (ctx, value, options) {\n if (value === undefined || value === null) return null;\n\n if (!Array.isArray(value)) return notAnArrayError();\n\n const itemConverter = ctx.typeRegistry.getConverter(this._itemType);\n let itemError;\n for (const ix in value) {\n itemError = itemConverter.validate(ctx, value[ix], options);\n if (itemError) return itemError;\n }\n};\n\nfunction notAnArrayError() {\n const err = new Error(g.f('Value is not an array.'));\n err.statusCode = 400;\n return err;\n}\n\nfunction validateConverterResult(result) {\n const isValid = typeof result === 'object' && ('error' in result || 'value' in result);\n if (isValid) return result;\n\n const err = new assert.AssertionError({\n message:\n 'Type conversion result should have \"error\" or \"value\" property. ' +\n 'Got ' +\n JSON.stringify(result) +\n ' instead.',\n });\n return { error: err };\n}\n"],"mappings":"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"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ const require_runtime = require("../../_virtual/_rolldown/runtime.js");
3
+ const require_lib_messages = require("../messages.js");
4
+ //#region src/lib/types/boolean.ts
5
+ var require_boolean = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
6
+ require("debug")("strong-remoting:http-coercion");
7
+ const g = require_lib_messages;
8
+ module.exports = {
9
+ fromTypedValue: function(ctx, value, options) {
10
+ const error = this.validate(ctx, value, options);
11
+ return error ? { error } : { value };
12
+ },
13
+ fromSloppyValue: function(ctx, value, options) {
14
+ if (value === "" || value === void 0) return { value: void 0 };
15
+ if (typeof value === "string") switch (value.toLowerCase()) {
16
+ case "false":
17
+ case "0": return { value: false };
18
+ case "true":
19
+ case "1": return { value: true };
20
+ }
21
+ return { error: invalidBooleanError() };
22
+ },
23
+ validate: function(ctx, value, options) {
24
+ if (value === void 0 || typeof value === "boolean") return null;
25
+ return invalidBooleanError();
26
+ }
27
+ };
28
+ function invalidBooleanError() {
29
+ const err = new Error(g.f("Value is not a boolean."));
30
+ err.statusCode = 400;
31
+ return err;
32
+ }
33
+ }));
34
+ //#endregion
35
+ module.exports = require_boolean();
36
+
37
+ //# sourceMappingURL=boolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.js","names":[],"sources":["../../../src/lib/types/boolean.ts"],"sourcesContent":["// Copyright IBM Corp. 2016,2017. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\nconst debug = require('debug')('strong-remoting:http-coercion');\nconst g = require('../messages');\n\nmodule.exports = {\n fromTypedValue: function (ctx, value, options) {\n const error = this.validate(ctx, value, options);\n return error ? { error: error } : { value: value };\n },\n\n fromSloppyValue: function (ctx, value, options) {\n if (value === '' || value === undefined) return { value: undefined };\n\n if (typeof value === 'string') {\n switch (value.toLowerCase()) {\n case 'false':\n case '0':\n return { value: false };\n case 'true':\n case '1':\n return { value: true };\n }\n }\n return { error: invalidBooleanError() };\n },\n\n validate: function (ctx, value, options) {\n if (value === undefined || typeof value === 'boolean') return null;\n\n return invalidBooleanError();\n },\n};\n\nfunction invalidBooleanError() {\n const err = new Error(g.f('Value is not a boolean.'));\n err.statusCode = 400;\n return err;\n}\n"],"mappings":";;;;;AAQc,SAAQ,QAAQ,CAAC,gCAAgC;CAC/D,MAAM,IAAA;AAEN,QAAO,UAAU;EACf,gBAAgB,SAAU,KAAK,OAAO,SAAS;GAC7C,MAAM,QAAQ,KAAK,SAAS,KAAK,OAAO,QAAQ;AAChD,UAAO,QAAQ,EAAS,OAAO,GAAG,EAAS,OAAO;;EAGpD,iBAAiB,SAAU,KAAK,OAAO,SAAS;AAC9C,OAAI,UAAU,MAAM,UAAU,KAAA,EAAW,QAAO,EAAE,OAAO,KAAA,GAAW;AAEpE,OAAI,OAAO,UAAU,SACnB,SAAQ,MAAM,aAAa,EAA3B;IACE,KAAK;IACL,KAAK,IACH,QAAO,EAAE,OAAO,OAAO;IACzB,KAAK;IACL,KAAK,IACH,QAAO,EAAE,OAAO,MAAM;;AAG5B,UAAO,EAAE,OAAO,qBAAqB,EAAE;;EAGzC,UAAU,SAAU,KAAK,OAAO,SAAS;AACvC,OAAI,UAAU,KAAA,KAAa,OAAO,UAAU,UAAW,QAAO;AAE9D,UAAO,qBAAqB;;EAE/B;CAED,SAAS,sBAAsB;EAC7B,MAAM,MAAM,IAAI,MAAM,EAAE,EAAE,0BAA0B,CAAC;AACrD,MAAI,aAAa;AACjB,SAAO"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ const require_runtime = require("../../_virtual/_rolldown/runtime.js");
3
+ const require_lib_messages = require("../messages.js");
4
+ //#region src/lib/types/date.ts
5
+ var require_date = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
6
+ require("debug")("strong-remoting:http-coercion");
7
+ const g = require_lib_messages;
8
+ module.exports = {
9
+ fromTypedValue: function(ctx, value, options) {
10
+ if (value === void 0) return { value };
11
+ if (value === null) return { error: invalidDateError() };
12
+ if (typeof value !== "number" && typeof value !== "string") return { error: invalidDateError() };
13
+ const result = new Date(value);
14
+ const error = this.validate(result);
15
+ return error ? { error } : { value: result };
16
+ },
17
+ fromSloppyValue: function(ctx, value, options) {
18
+ if (value === "") return { value: void 0 };
19
+ if (/^-?[0-9]+$/.test(value)) value = +value;
20
+ return this.fromTypedValue(ctx, value, options);
21
+ },
22
+ validate: function(ctx, value, options) {
23
+ if (value === void 0) return null;
24
+ if (value instanceof Date && !Number.isNaN(value.getTime())) return null;
25
+ return invalidDateError();
26
+ }
27
+ };
28
+ function invalidDateError() {
29
+ const err = new Error(g.f("Value is not a valid date."));
30
+ err.statusCode = 400;
31
+ return err;
32
+ }
33
+ }));
34
+ //#endregion
35
+ module.exports = require_date();
36
+
37
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.js","names":[],"sources":["../../../src/lib/types/date.ts"],"sourcesContent":["// Copyright IBM Corp. 2016,2017. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\nconst debug = require('debug')('strong-remoting:http-coercion');\nconst g = require('../messages');\n\nmodule.exports = {\n fromTypedValue: function (ctx, value, options) {\n if (value === undefined) return { value: value };\n\n if (value === null) return { error: invalidDateError() };\n\n if (typeof value !== 'number' && typeof value !== 'string')\n return { error: invalidDateError() };\n\n const result = new Date(value);\n const error = this.validate(result);\n return error ? { error: error } : { value: result };\n },\n\n fromSloppyValue: function (ctx, value, options) {\n if (value === '') return { value: undefined };\n\n if (/^-?[0-9]+$/.test(value)) {\n // convert a timestamp string to a number\n // that way ?from=0 produces 1970-01-01T00:00:00.000Z\n value = +value;\n }\n\n return this.fromTypedValue(ctx, value, options);\n },\n\n validate: function (ctx, value, options) {\n if (value === undefined) return null;\n\n if (value instanceof Date && !Number.isNaN(value.getTime())) return null;\n\n return invalidDateError();\n },\n};\n\nfunction invalidDateError() {\n const err = new Error(g.f('Value is not a valid date.'));\n err.statusCode = 400;\n return err;\n}\n"],"mappings":";;;;;AAQc,SAAQ,QAAQ,CAAC,gCAAgC;CAC/D,MAAM,IAAA;AAEN,QAAO,UAAU;EACf,gBAAgB,SAAU,KAAK,OAAO,SAAS;AAC7C,OAAI,UAAU,KAAA,EAAW,QAAO,EAAS,OAAO;AAEhD,OAAI,UAAU,KAAM,QAAO,EAAE,OAAO,kBAAkB,EAAE;AAExD,OAAI,OAAO,UAAU,YAAY,OAAO,UAAU,SAChD,QAAO,EAAE,OAAO,kBAAkB,EAAE;GAEtC,MAAM,SAAS,IAAI,KAAK,MAAM;GAC9B,MAAM,QAAQ,KAAK,SAAS,OAAO;AACnC,UAAO,QAAQ,EAAS,OAAO,GAAG,EAAE,OAAO,QAAQ;;EAGrD,iBAAiB,SAAU,KAAK,OAAO,SAAS;AAC9C,OAAI,UAAU,GAAI,QAAO,EAAE,OAAO,KAAA,GAAW;AAE7C,OAAI,aAAa,KAAK,MAAM,CAG1B,SAAQ,CAAC;AAGX,UAAO,KAAK,eAAe,KAAK,OAAO,QAAQ;;EAGjD,UAAU,SAAU,KAAK,OAAO,SAAS;AACvC,OAAI,UAAU,KAAA,EAAW,QAAO;AAEhC,OAAI,iBAAiB,QAAQ,CAAC,OAAO,MAAM,MAAM,SAAS,CAAC,CAAE,QAAO;AAEpE,UAAO,kBAAkB;;EAE5B;CAED,SAAS,mBAAmB;EAC1B,MAAM,MAAM,IAAI,MAAM,EAAE,EAAE,6BAA6B,CAAC;AACxD,MAAI,aAAa;AACjB,SAAO"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ const require_runtime = require("../../_virtual/_rolldown/runtime.js");
3
+ const require_lib_messages = require("../messages.js");
4
+ const require_lib_looks_like_json = require("../looks-like-json.js");
5
+ //#region src/lib/types/geopoint.ts
6
+ var require_geopoint = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
7
+ const debug = require("debug")("strong-remoting:http-coercion");
8
+ const g = require_lib_messages;
9
+ const GeoPoint = require("loopback-datatype-geopoint");
10
+ const looksLikeJson = require_lib_looks_like_json.looksLikeJson;
11
+ module.exports = {
12
+ fromTypedValue: function(ctx, value, options) {
13
+ if (value === void 0) return { value };
14
+ const error = this.validate(ctx, value, options);
15
+ return error ? { error } : { value: new GeoPoint(value) };
16
+ },
17
+ fromSloppyValue: function(ctx, value, options) {
18
+ if (value === void 0 || value === "") return { value: void 0 };
19
+ if (value === null || value === "null") return { value: null };
20
+ if (looksLikeJson(value)) {
21
+ const result = parseJson(value);
22
+ if (result instanceof Error) return { error: result };
23
+ return this.fromTypedValue(ctx, result, options);
24
+ }
25
+ if (typeof value === "object") {
26
+ const result = coerceArrayOrObject(value);
27
+ return this.fromTypedValue(ctx, result, options);
28
+ }
29
+ return this.fromTypedValue(ctx, value, options);
30
+ },
31
+ validate: function(ctx, value, options) {
32
+ if (value === void 0) return null;
33
+ try {
34
+ new GeoPoint(value);
35
+ return null;
36
+ } catch (e) {
37
+ const err = new Error(e.message);
38
+ err.statusCode = 400;
39
+ return err;
40
+ }
41
+ }
42
+ };
43
+ function parseJson(value) {
44
+ try {
45
+ const result = JSON.parse(value);
46
+ debug("parsed %j as JSON: %j", value, result);
47
+ return result;
48
+ } catch (ex) {
49
+ debug("Cannot parse object value %j. %s", value, ex);
50
+ const err = new Error(g.f("Cannot parse JSON-encoded object value."));
51
+ err.statusCode = 400;
52
+ return err;
53
+ }
54
+ }
55
+ function coerceArrayOrObject(value) {
56
+ const result = {};
57
+ if (Array.isArray(value)) return value.map(Number);
58
+ for (const key in value) {
59
+ const val = value[key];
60
+ result[key] = Number(val);
61
+ }
62
+ return result;
63
+ }
64
+ }));
65
+ //#endregion
66
+ module.exports = require_geopoint();
67
+
68
+ //# sourceMappingURL=geopoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geopoint.js","names":[],"sources":["../../../src/lib/types/geopoint.ts"],"sourcesContent":["// Copyright IBM Corp. 2016,2017. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\nconst debug = require('debug')('strong-remoting:http-coercion');\nconst g = require('../messages');\nconst GeoPoint = require('loopback-datatype-geopoint');\nconst looksLikeJson = require('../looks-like-json').looksLikeJson;\n\nmodule.exports = {\n fromTypedValue: function (ctx, value, options) {\n if (value === undefined) return { value: value };\n const error = this.validate(ctx, value, options);\n return error ? { error: error } : { value: new GeoPoint(value) };\n },\n\n fromSloppyValue: function (ctx, value, options) {\n if (value === undefined || value === '') {\n // undefined was chosen so that it plays well with ES6 default parameters.\n return { value: undefined };\n }\n\n if (value === null || value === 'null') return { value: null };\n\n if (looksLikeJson(value)) {\n const result = parseJson(value);\n if (result instanceof Error) return { error: result };\n return this.fromTypedValue(ctx, result, options);\n }\n\n // coerce input from 'arg[lat]=2.5&arg[lng]=2' or 'arg[0]=2.5&arg[1]=2\n if (typeof value === 'object') {\n const result = coerceArrayOrObject(value);\n return this.fromTypedValue(ctx, result, options);\n }\n return this.fromTypedValue(ctx, value, options);\n },\n\n validate: function (ctx, value, options) {\n if (value === undefined) return null;\n try {\n new GeoPoint(value);\n return null;\n } catch (e) {\n const err = new Error(e.message);\n err.statusCode = 400;\n return err;\n }\n },\n};\n\nfunction parseJson(value) {\n try {\n const result = JSON.parse(value);\n debug('parsed %j as JSON: %j', value, result);\n return result;\n } catch (ex) {\n debug('Cannot parse object value %j. %s', value, ex);\n const err = new Error(g.f('Cannot parse JSON-encoded object value.'));\n err.statusCode = 400;\n return err;\n }\n}\n\nfunction coerceArrayOrObject(value) {\n const result = {};\n\n if (Array.isArray(value)) {\n return value.map(Number);\n }\n\n for (const key in value) {\n const val = value[key];\n result[key] = Number(val);\n }\n return result;\n}\n"],"mappings":";;;;;;CAQA,MAAM,QAAQ,QAAQ,QAAQ,CAAC,gCAAgC;CAC/D,MAAM,IAAA;CACN,MAAM,WAAW,QAAQ,6BAA6B;CACtD,MAAM,gBAAA,4BAA8C;AAEpD,QAAO,UAAU;EACf,gBAAgB,SAAU,KAAK,OAAO,SAAS;AAC7C,OAAI,UAAU,KAAA,EAAW,QAAO,EAAS,OAAO;GAChD,MAAM,QAAQ,KAAK,SAAS,KAAK,OAAO,QAAQ;AAChD,UAAO,QAAQ,EAAS,OAAO,GAAG,EAAE,OAAO,IAAI,SAAS,MAAM,EAAE;;EAGlE,iBAAiB,SAAU,KAAK,OAAO,SAAS;AAC9C,OAAI,UAAU,KAAA,KAAa,UAAU,GAEnC,QAAO,EAAE,OAAO,KAAA,GAAW;AAG7B,OAAI,UAAU,QAAQ,UAAU,OAAQ,QAAO,EAAE,OAAO,MAAM;AAE9D,OAAI,cAAc,MAAM,EAAE;IACxB,MAAM,SAAS,UAAU,MAAM;AAC/B,QAAI,kBAAkB,MAAO,QAAO,EAAE,OAAO,QAAQ;AACrD,WAAO,KAAK,eAAe,KAAK,QAAQ,QAAQ;;AAIlD,OAAI,OAAO,UAAU,UAAU;IAC7B,MAAM,SAAS,oBAAoB,MAAM;AACzC,WAAO,KAAK,eAAe,KAAK,QAAQ,QAAQ;;AAElD,UAAO,KAAK,eAAe,KAAK,OAAO,QAAQ;;EAGjD,UAAU,SAAU,KAAK,OAAO,SAAS;AACvC,OAAI,UAAU,KAAA,EAAW,QAAO;AAChC,OAAI;AACF,QAAI,SAAS,MAAM;AACnB,WAAO;YACA,GAAG;IACV,MAAM,MAAM,IAAI,MAAM,EAAE,QAAQ;AAChC,QAAI,aAAa;AACjB,WAAO;;;EAGZ;CAED,SAAS,UAAU,OAAO;AACxB,MAAI;GACF,MAAM,SAAS,KAAK,MAAM,MAAM;AAChC,SAAM,yBAAyB,OAAO,OAAO;AAC7C,UAAO;WACA,IAAI;AACX,SAAM,oCAAoC,OAAO,GAAG;GACpD,MAAM,MAAM,IAAI,MAAM,EAAE,EAAE,0CAA0C,CAAC;AACrE,OAAI,aAAa;AACjB,UAAO;;;CAIX,SAAS,oBAAoB,OAAO;EAClC,MAAM,SAAS,EAAE;AAEjB,MAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,IAAI,OAAO;AAG1B,OAAK,MAAM,OAAO,OAAO;GACvB,MAAM,MAAM,MAAM;AAClB,UAAO,OAAO,OAAO,IAAI;;AAE3B,SAAO"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ const require_runtime = require("../../_virtual/_rolldown/runtime.js");
3
+ const require_lib_messages = require("../messages.js");
4
+ const require_lib_number_checks = require("../number-checks.js");
5
+ const require_lib_types_number = require("./number.js");
6
+ //#region src/lib/types/integer.ts
7
+ var require_integer = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
8
+ require("debug")("strong-remoting:http-coercion");
9
+ const g = require_lib_messages;
10
+ const isSafeInteger = require_lib_number_checks.isSafeInteger;
11
+ const numberConverter = require_lib_types_number;
12
+ module.exports = {
13
+ fromTypedValue: function(ctx, value, options) {
14
+ const error = this.validate(ctx, value, options);
15
+ return error ? { error } : { value };
16
+ },
17
+ fromSloppyValue: function(ctx, value, options) {
18
+ const result = numberConverter.fromSloppyValue(ctx, value);
19
+ if (result.error) return result;
20
+ return this.fromTypedValue(ctx, result.value);
21
+ },
22
+ validate: function(ctx, value, options) {
23
+ if (value === void 0) return null;
24
+ let err = numberConverter.validate(ctx, value, options);
25
+ if (err) return err;
26
+ if (isSafeInteger(value)) return null;
27
+ err = new Error(g.f("Value is not a safe integer."));
28
+ err.statusCode = 400;
29
+ return err;
30
+ }
31
+ };
32
+ }));
33
+ //#endregion
34
+ module.exports = require_integer();
35
+
36
+ //# sourceMappingURL=integer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integer.js","names":[],"sources":["../../../src/lib/types/integer.ts"],"sourcesContent":["// Copyright IBM Corp. 2016,2017. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\nconst debug = require('debug')('strong-remoting:http-coercion');\nconst g = require('../messages');\nconst isSafeInteger = require('../number-checks').isSafeInteger;\nconst numberConverter = require('./number');\n\nmodule.exports = {\n fromTypedValue: function (ctx, value, options) {\n const error = this.validate(ctx, value, options);\n return error ? { error: error } : { value: value };\n },\n\n fromSloppyValue: function (ctx, value, options) {\n const result = numberConverter.fromSloppyValue(ctx, value);\n if (result.error) return result;\n return this.fromTypedValue(ctx, result.value);\n },\n\n validate: function (ctx, value, options) {\n if (value === undefined) return null;\n\n let err = numberConverter.validate(ctx, value, options);\n if (err) return err;\n\n if (isSafeInteger(value)) return null;\n\n err = new Error(g.f('Value is not a safe integer.'));\n err.statusCode = 400;\n return err;\n },\n};\n"],"mappings":";;;;;;;AAQc,SAAQ,QAAQ,CAAC,gCAAgC;CAC/D,MAAM,IAAA;CACN,MAAM,gBAAA,0BAA4C;CAClD,MAAM,kBAAA;AAEN,QAAO,UAAU;EACf,gBAAgB,SAAU,KAAK,OAAO,SAAS;GAC7C,MAAM,QAAQ,KAAK,SAAS,KAAK,OAAO,QAAQ;AAChD,UAAO,QAAQ,EAAS,OAAO,GAAG,EAAS,OAAO;;EAGpD,iBAAiB,SAAU,KAAK,OAAO,SAAS;GAC9C,MAAM,SAAS,gBAAgB,gBAAgB,KAAK,MAAM;AAC1D,OAAI,OAAO,MAAO,QAAO;AACzB,UAAO,KAAK,eAAe,KAAK,OAAO,MAAM;;EAG/C,UAAU,SAAU,KAAK,OAAO,SAAS;AACvC,OAAI,UAAU,KAAA,EAAW,QAAO;GAEhC,IAAI,MAAM,gBAAgB,SAAS,KAAK,OAAO,QAAQ;AACvD,OAAI,IAAK,QAAO;AAEhB,OAAI,cAAc,MAAM,CAAE,QAAO;AAEjC,SAAM,IAAI,MAAM,EAAE,EAAE,+BAA+B,CAAC;AACpD,OAAI,aAAa;AACjB,UAAO;;EAEV"}
@@ -0,0 +1 @@
1
+ export { };