@apollo/federation-internals 2.7.4-testing.1 → 2.7.5

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.
@@ -1,133 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONNECT_VERSIONS = exports.ConnectSpecDefinition = exports.connectIdentity = void 0;
4
- const graphql_1 = require("graphql");
5
- const coreSpec_1 = require("./coreSpec");
6
- const definitions_1 = require("../definitions");
7
- const knownCoreFeatures_1 = require("../knownCoreFeatures");
8
- const directiveAndTypeSpecification_1 = require("../directiveAndTypeSpecification");
9
- const error_1 = require("../error");
10
- exports.connectIdentity = 'https://specs.apollo.dev/connect';
11
- const CONNECT = "connect";
12
- const SOURCE = "source";
13
- const URL_PATH_TEMPLATE = "URLPathTemplate";
14
- const JSON_SELECTION = "JSONSelection";
15
- const CONNECT_HTTP = "ConnectHTTP";
16
- const SOURCE_HTTP = "SourceHTTP";
17
- const HTTP_HEADER_MAPPING = "HTTPHeaderMapping";
18
- class ConnectSpecDefinition extends coreSpec_1.FeatureDefinition {
19
- constructor(version, minimumFederationVersion) {
20
- super(new coreSpec_1.FeatureUrl(exports.connectIdentity, CONNECT, version), minimumFederationVersion);
21
- this.minimumFederationVersion = minimumFederationVersion;
22
- this.registerDirective((0, directiveAndTypeSpecification_1.createDirectiveSpecification)({
23
- name: CONNECT,
24
- locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
25
- repeatable: true,
26
- composes: false,
27
- }));
28
- this.registerDirective((0, directiveAndTypeSpecification_1.createDirectiveSpecification)({
29
- name: SOURCE,
30
- locations: [graphql_1.DirectiveLocation.SCHEMA],
31
- repeatable: true,
32
- composes: false,
33
- }));
34
- this.registerType({ name: URL_PATH_TEMPLATE, checkOrAdd: () => [] });
35
- this.registerType({ name: JSON_SELECTION, checkOrAdd: () => [] });
36
- this.registerType({ name: CONNECT_HTTP, checkOrAdd: () => [] });
37
- this.registerType({ name: SOURCE_HTTP, checkOrAdd: () => [] });
38
- this.registerType({ name: HTTP_HEADER_MAPPING, checkOrAdd: () => [] });
39
- }
40
- addElementsToSchema(schema) {
41
- const URLPathTemplate = this.addScalarType(schema, URL_PATH_TEMPLATE);
42
- const JSONSelection = this.addScalarType(schema, JSON_SELECTION);
43
- const connect = this.addDirective(schema, CONNECT).addLocations(graphql_1.DirectiveLocation.FIELD_DEFINITION);
44
- connect.repeatable = true;
45
- connect.addArgument(SOURCE, schema.stringType());
46
- const HTTPHeaderMapping = schema.addType(new definitions_1.InputObjectType(this.typeNameInSchema(schema, HTTP_HEADER_MAPPING)));
47
- HTTPHeaderMapping.addField(new definitions_1.InputFieldDefinition('name')).type =
48
- new definitions_1.NonNullType(schema.stringType());
49
- HTTPHeaderMapping.addField(new definitions_1.InputFieldDefinition('as')).type =
50
- schema.stringType();
51
- HTTPHeaderMapping.addField(new definitions_1.InputFieldDefinition('value')).type =
52
- schema.stringType();
53
- const ConnectHTTP = schema.addType(new definitions_1.InputObjectType(this.typeNameInSchema(schema, CONNECT_HTTP)));
54
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('GET')).type = URLPathTemplate;
55
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('POST')).type = URLPathTemplate;
56
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('PUT')).type = URLPathTemplate;
57
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('PATCH')).type = URLPathTemplate;
58
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('DELETE')).type = URLPathTemplate;
59
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('body')).type = JSONSelection;
60
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('headers')).type =
61
- new definitions_1.ListType(new definitions_1.NonNullType(HTTPHeaderMapping));
62
- connect.addArgument('http', ConnectHTTP);
63
- connect.addArgument('selection', JSONSelection);
64
- const source = this.addDirective(schema, SOURCE).addLocations(graphql_1.DirectiveLocation.SCHEMA);
65
- source.repeatable = true;
66
- source.addArgument('name', new definitions_1.NonNullType(schema.stringType()));
67
- const SourceHTTP = schema.addType(new definitions_1.InputObjectType(this.typeNameInSchema(schema, SOURCE_HTTP)));
68
- SourceHTTP.addField(new definitions_1.InputFieldDefinition('baseURL')).type =
69
- new definitions_1.NonNullType(schema.stringType());
70
- SourceHTTP.addField(new definitions_1.InputFieldDefinition('headers')).type =
71
- new definitions_1.ListType(new definitions_1.NonNullType(HTTPHeaderMapping));
72
- source.addArgument('http', SourceHTTP);
73
- return [];
74
- }
75
- get defaultCorePurpose() {
76
- return 'EXECUTION';
77
- }
78
- sourceDirective(schema) {
79
- return this.directive(schema, 'source');
80
- }
81
- connectDirective(schema) {
82
- return this.directive(schema, 'connect');
83
- }
84
- getConnectDirectives(schema) {
85
- const result = {};
86
- schema.schemaDefinition.appliedDirectivesOf('link')
87
- .forEach(linkDirective => {
88
- const { url, import: imports } = linkDirective.arguments();
89
- const featureUrl = coreSpec_1.FeatureUrl.maybeParse(url);
90
- if (imports && featureUrl && featureUrl.identity === exports.connectIdentity) {
91
- imports.forEach(nameOrRename => {
92
- const originalName = typeof nameOrRename === 'string' ? nameOrRename : nameOrRename.name;
93
- const importedName = typeof nameOrRename === 'string' ? nameOrRename : nameOrRename.as || originalName;
94
- const importedNameWithoutAt = importedName.replace(/^@/, '');
95
- if (originalName === '@source') {
96
- result.source = schema.directive(importedNameWithoutAt);
97
- }
98
- else if (originalName === '@connect') {
99
- result.connect = schema.directive(importedNameWithoutAt);
100
- }
101
- });
102
- }
103
- });
104
- return result;
105
- }
106
- validateSubgraphSchema(schema) {
107
- const errors = super.validateSubgraphSchema(schema);
108
- const { source: sourceAPI, connect: sourceField, } = this.getConnectDirectives(schema);
109
- if (!(sourceAPI || sourceField)) {
110
- return [];
111
- }
112
- errors.push(...this.validateConnectDirectives(schema));
113
- return errors;
114
- }
115
- validateConnectDirectives(schema) {
116
- try {
117
- const { validate_connect_directives } = require('../../wasm/node');
118
- const source = (0, graphql_1.print)(schema.toAST());
119
- return validate_connect_directives(source).map(raw => error_1.ERRORS.WASM_VALIDATION_ERROR.err(raw.message, {
120
- source: new graphql_1.Source(source),
121
- positions: [raw.index],
122
- }));
123
- }
124
- catch (e) {
125
- return [error_1.ERRORS.WASM_LOAD_ERROR.err(`Error loading WASM module: ${e.message || e}`)];
126
- }
127
- }
128
- }
129
- exports.ConnectSpecDefinition = ConnectSpecDefinition;
130
- exports.CONNECT_VERSIONS = new coreSpec_1.FeatureDefinitions(exports.connectIdentity)
131
- .add(new ConnectSpecDefinition(new coreSpec_1.FeatureVersion(0, 1), new coreSpec_1.FeatureVersion(2, 8)));
132
- (0, knownCoreFeatures_1.registerKnownFeature)(exports.CONNECT_VERSIONS);
133
- //# sourceMappingURL=connectSpec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connectSpec.js","sourceRoot":"","sources":["../../src/specs/connectSpec.ts"],"names":[],"mappings":";;;AAAA,qCAAyE;AACzE,yCAA+H;AAC/H,gDAOwB;AACxB,4DAA4D;AAC5D,oFAAgF;AAChF,oCAAkC;AAErB,QAAA,eAAe,GAAG,kCAAkC,CAAC;AAElE,MAAM,OAAO,GAAG,SAAS,CAAC;AAC1B,MAAM,MAAM,GAAG,QAAQ,CAAC;AACxB,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAC5C,MAAM,cAAc,GAAG,eAAe,CAAC;AACvC,MAAM,YAAY,GAAG,aAAa,CAAC;AACnC,MAAM,WAAW,GAAG,YAAY,CAAC;AACjC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAEhD,MAAa,qBAAsB,SAAQ,4BAAiB;IAC1D,YAAY,OAAuB,EAAW,wBAAwC;QACpF,KAAK,CAAC,IAAI,qBAAU,CAAC,uBAAe,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,wBAAwB,CAAC,CAAC;QADvC,6BAAwB,GAAxB,wBAAwB,CAAgB;QAGpF,IAAI,CAAC,iBAAiB,CAAC,IAAA,4DAA4B,EAAC;YA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I,CAAC,EAAE,CAC/C,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AA9LD,sDA8LC;AAqCY,QAAA,gBAAgB,GAAG,IAAI,6BAAkB,CAAwB,uBAAe,CAAC;KAC3F,GAAG,CAAC,IAAI,qBAAqB,CAAC,IAAI,yBAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,yBAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAEtF,IAAA,wCAAoB,EAAC,wBAAgB,CAAC,CAAC"}
@@ -1,255 +0,0 @@
1
- import { DirectiveLocation, GraphQLError, Source, print } from 'graphql';
2
- import { CorePurpose, FeatureDefinition, FeatureDefinitions, FeatureUrl, FeatureVersion, LinkDirectiveArgs } from "./coreSpec";
3
- import {
4
- Schema,
5
- NonNullType,
6
- InputObjectType,
7
- InputFieldDefinition,
8
- ListType,
9
- DirectiveDefinition,
10
- } from '../definitions';
11
- import { registerKnownFeature } from '../knownCoreFeatures';
12
- import { createDirectiveSpecification } from '../directiveAndTypeSpecification';
13
- import { ERRORS } from '../error';
14
-
15
- export const connectIdentity = 'https://specs.apollo.dev/connect';
16
-
17
- const CONNECT = "connect";
18
- const SOURCE = "source";
19
- const URL_PATH_TEMPLATE = "URLPathTemplate";
20
- const JSON_SELECTION = "JSONSelection";
21
- const CONNECT_HTTP = "ConnectHTTP";
22
- const SOURCE_HTTP = "SourceHTTP";
23
- const HTTP_HEADER_MAPPING = "HTTPHeaderMapping";
24
-
25
- export class ConnectSpecDefinition extends FeatureDefinition {
26
- constructor(version: FeatureVersion, readonly minimumFederationVersion: FeatureVersion) {
27
- super(new FeatureUrl(connectIdentity, CONNECT, version), minimumFederationVersion);
28
-
29
- this.registerDirective(createDirectiveSpecification({
30
- name: CONNECT,
31
- locations: [DirectiveLocation.FIELD_DEFINITION],
32
- repeatable: true,
33
- // We "compose" these directives using the `@join__directive` mechanism,
34
- // so they do not need to be composed in the way passing `composes: true`
35
- // here implies.
36
- composes: false,
37
- }));
38
-
39
- this.registerDirective(createDirectiveSpecification({
40
- name: SOURCE,
41
- locations: [DirectiveLocation.SCHEMA],
42
- repeatable: true,
43
- composes: false,
44
- }));
45
-
46
- this.registerType({ name: URL_PATH_TEMPLATE, checkOrAdd: () => [] });
47
- this.registerType({ name: JSON_SELECTION, checkOrAdd: () => [] });
48
- this.registerType({ name: CONNECT_HTTP, checkOrAdd: () => [] });
49
- this.registerType({ name: SOURCE_HTTP, checkOrAdd: () => [] });
50
- this.registerType({ name: HTTP_HEADER_MAPPING, checkOrAdd: () => [] });
51
- }
52
-
53
- addElementsToSchema(schema: Schema): GraphQLError[] {
54
- /* scalar URLPathTemplate */
55
- const URLPathTemplate = this.addScalarType(schema, URL_PATH_TEMPLATE);
56
-
57
- /* scalar JSONSelection */
58
- const JSONSelection = this.addScalarType(schema, JSON_SELECTION);
59
-
60
- /*
61
- directive @connect(
62
- source: String
63
- http: ConnectHTTP
64
- selection: JSONSelection!
65
- ) repeatable on FIELD_DEFINITION
66
- */
67
- const connect = this.addDirective(schema, CONNECT).addLocations(DirectiveLocation.FIELD_DEFINITION);
68
- connect.repeatable = true;
69
-
70
- connect.addArgument(SOURCE, schema.stringType());
71
-
72
- /*
73
- input HTTPHeaderMapping {
74
- name: String!
75
- as: String
76
- value: String
77
- }
78
- */
79
- const HTTPHeaderMapping = schema.addType(new InputObjectType(this.typeNameInSchema(schema, HTTP_HEADER_MAPPING)!));
80
- HTTPHeaderMapping.addField(new InputFieldDefinition('name')).type =
81
- new NonNullType(schema.stringType());
82
- HTTPHeaderMapping.addField(new InputFieldDefinition('as')).type =
83
- schema.stringType();
84
- HTTPHeaderMapping.addField(new InputFieldDefinition('value')).type =
85
- schema.stringType();
86
-
87
- /*
88
- input ConnectHTTP {
89
- GET: URLPathTemplate
90
- POST: URLPathTemplate
91
- PUT: URLPathTemplate
92
- PATCH: URLPathTemplate
93
- DELETE: URLPathTemplate
94
- body: JSONSelection
95
- headers: [HTTPHeaderMapping!]
96
- }
97
- */
98
- const ConnectHTTP = schema.addType(new InputObjectType(this.typeNameInSchema(schema, CONNECT_HTTP)!));
99
- ConnectHTTP.addField(new InputFieldDefinition('GET')).type = URLPathTemplate;
100
- ConnectHTTP.addField(new InputFieldDefinition('POST')).type = URLPathTemplate;
101
- ConnectHTTP.addField(new InputFieldDefinition('PUT')).type = URLPathTemplate;
102
- ConnectHTTP.addField(new InputFieldDefinition('PATCH')).type = URLPathTemplate;
103
- ConnectHTTP.addField(new InputFieldDefinition('DELETE')).type = URLPathTemplate;
104
- ConnectHTTP.addField(new InputFieldDefinition('body')).type = JSONSelection;
105
- ConnectHTTP.addField(new InputFieldDefinition('headers')).type =
106
- new ListType(new NonNullType(HTTPHeaderMapping));
107
- connect.addArgument('http', ConnectHTTP);
108
-
109
- connect.addArgument('selection', JSONSelection);
110
-
111
- /*
112
- directive @source(
113
- name: String!
114
- http: ConnectHTTP
115
- ) repeatable on SCHEMA
116
- */
117
- const source = this.addDirective(schema, SOURCE).addLocations(
118
- DirectiveLocation.SCHEMA,
119
- );
120
- source.repeatable = true;
121
- source.addArgument('name', new NonNullType(schema.stringType()));
122
-
123
- /*
124
- input SourceHTTP {
125
- baseURL: String!
126
- headers: [HTTPHeaderMapping!]
127
- }
128
- */
129
- const SourceHTTP = schema.addType(new InputObjectType(this.typeNameInSchema(schema, SOURCE_HTTP)!));
130
- SourceHTTP.addField(new InputFieldDefinition('baseURL')).type =
131
- new NonNullType(schema.stringType());
132
- SourceHTTP.addField(new InputFieldDefinition('headers')).type =
133
- new ListType(new NonNullType(HTTPHeaderMapping));
134
-
135
- source.addArgument('http', SourceHTTP);
136
-
137
- return [];
138
- }
139
-
140
- get defaultCorePurpose(): CorePurpose {
141
- return 'EXECUTION';
142
- }
143
-
144
- sourceDirective(schema: Schema) {
145
- return this.directive<SourceDirectiveArgs>(schema, 'source')!;
146
- }
147
-
148
- connectDirective(schema: Schema) {
149
- return this.directive<ConnectDirectiveArgs>(schema, 'connect')!;
150
- }
151
-
152
- private getConnectDirectives(schema: Schema) {
153
- const result: {
154
- source?: DirectiveDefinition<SourceDirectiveArgs>;
155
- connect?: DirectiveDefinition<ConnectDirectiveArgs>;
156
- } = {};
157
-
158
- schema.schemaDefinition.appliedDirectivesOf<LinkDirectiveArgs>('link')
159
- .forEach(linkDirective => {
160
- const { url, import: imports } = linkDirective.arguments();
161
- const featureUrl = FeatureUrl.maybeParse(url);
162
- if (imports && featureUrl && featureUrl.identity === connectIdentity) {
163
- imports.forEach(nameOrRename => {
164
- const originalName = typeof nameOrRename === 'string' ? nameOrRename : nameOrRename.name;
165
- const importedName = typeof nameOrRename === 'string' ? nameOrRename : nameOrRename.as || originalName;
166
- const importedNameWithoutAt = importedName.replace(/^@/, '');
167
-
168
- if (originalName === '@source') {
169
- result.source = schema.directive(importedNameWithoutAt) as DirectiveDefinition<SourceDirectiveArgs>;
170
- } else if (originalName === '@connect') {
171
- result.connect = schema.directive(importedNameWithoutAt) as DirectiveDefinition<ConnectDirectiveArgs>;
172
- }
173
- });
174
- }
175
- });
176
-
177
- return result;
178
- }
179
-
180
- override validateSubgraphSchema(schema: Schema): GraphQLError[] {
181
- const errors = super.validateSubgraphSchema(schema);
182
- const {
183
- source: sourceAPI,
184
- connect: sourceField,
185
- } = this.getConnectDirectives(schema);
186
-
187
- if (!(sourceAPI || sourceField)) {
188
- // If none of the @source* directives are present, nothing needs
189
- // validating.
190
- return [];
191
- }
192
-
193
- errors.push(...this.validateConnectDirectives(schema));
194
-
195
- return errors;
196
- }
197
-
198
- private validateConnectDirectives(schema: Schema): GraphQLError[] {
199
- try {
200
- const { validate_connect_directives } =
201
- require('../../wasm/node') as typeof import('../../wasm/node');
202
- const source = print(schema.toAST());
203
- return validate_connect_directives(source).map(
204
- raw => ERRORS.WASM_VALIDATION_ERROR.err(raw.message, {
205
- source: new Source(source),
206
- positions: [raw.index],
207
- }),
208
- );
209
- } catch (e: any) {
210
- return [ERRORS.WASM_LOAD_ERROR.err(
211
- `Error loading WASM module: ${e.message || e}`,
212
- )];
213
- }
214
- }
215
- }
216
-
217
- export type SourceDirectiveArgs = {
218
- name: string;
219
- http?: SourceDirectiveHTTP;
220
- };
221
-
222
- export type SourceDirectiveHTTP = {
223
- baseURL: string;
224
- headers?: HTTPHeaderMapping[];
225
- };
226
-
227
- type HTTPHeaderMapping = {
228
- name: string;
229
- as?: string;
230
- value?: string;
231
- };
232
-
233
- type URLPathTemplate = string;
234
- type JSONSelection = string;
235
-
236
- export type ConnectDirectiveArgs = {
237
- source: string;
238
- http?: ConnectDirectiveHTTP;
239
- selection?: JSONSelection;
240
- };
241
-
242
- export type ConnectDirectiveHTTP = {
243
- GET?: URLPathTemplate;
244
- POST?: URLPathTemplate;
245
- PUT?: URLPathTemplate;
246
- PATCH?: URLPathTemplate;
247
- DELETE?: URLPathTemplate;
248
- body?: JSONSelection;
249
- headers?: HTTPHeaderMapping[];
250
- };
251
-
252
- export const CONNECT_VERSIONS = new FeatureDefinitions<ConnectSpecDefinition>(connectIdentity)
253
- .add(new ConnectSpecDefinition(new FeatureVersion(0, 1), new FeatureVersion(2, 8)));
254
-
255
- registerKnownFeature(CONNECT_VERSIONS);
@@ -1,7 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- /**
4
- * @param {string} schema
5
- * @returns {any[]}
6
- */
7
- export function validate_connect_directives(schema: string): any[];
@@ -1,278 +0,0 @@
1
- let imports = {};
2
- imports['__wbindgen_placeholder__'] = module.exports;
3
- let wasm;
4
- const { TextDecoder, TextEncoder } = require(`util`);
5
-
6
- const heap = new Array(128).fill(undefined);
7
-
8
- heap.push(undefined, null, true, false);
9
-
10
- function getObject(idx) { return heap[idx]; }
11
-
12
- let heap_next = heap.length;
13
-
14
- function dropObject(idx) {
15
- if (idx < 132) return;
16
- heap[idx] = heap_next;
17
- heap_next = idx;
18
- }
19
-
20
- function takeObject(idx) {
21
- const ret = getObject(idx);
22
- dropObject(idx);
23
- return ret;
24
- }
25
-
26
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
27
-
28
- cachedTextDecoder.decode();
29
-
30
- let cachedUint8Memory0 = null;
31
-
32
- function getUint8Memory0() {
33
- if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
34
- cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
35
- }
36
- return cachedUint8Memory0;
37
- }
38
-
39
- function getStringFromWasm0(ptr, len) {
40
- ptr = ptr >>> 0;
41
- return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
42
- }
43
-
44
- function addHeapObject(obj) {
45
- if (heap_next === heap.length) heap.push(heap.length + 1);
46
- const idx = heap_next;
47
- heap_next = heap[idx];
48
-
49
- heap[idx] = obj;
50
- return idx;
51
- }
52
-
53
- function debugString(val) {
54
- // primitive types
55
- const type = typeof val;
56
- if (type == 'number' || type == 'boolean' || val == null) {
57
- return `${val}`;
58
- }
59
- if (type == 'string') {
60
- return `"${val}"`;
61
- }
62
- if (type == 'symbol') {
63
- const description = val.description;
64
- if (description == null) {
65
- return 'Symbol';
66
- } else {
67
- return `Symbol(${description})`;
68
- }
69
- }
70
- if (type == 'function') {
71
- const name = val.name;
72
- if (typeof name == 'string' && name.length > 0) {
73
- return `Function(${name})`;
74
- } else {
75
- return 'Function';
76
- }
77
- }
78
- // objects
79
- if (Array.isArray(val)) {
80
- const length = val.length;
81
- let debug = '[';
82
- if (length > 0) {
83
- debug += debugString(val[0]);
84
- }
85
- for(let i = 1; i < length; i++) {
86
- debug += ', ' + debugString(val[i]);
87
- }
88
- debug += ']';
89
- return debug;
90
- }
91
- // Test for built-in
92
- const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
93
- let className;
94
- if (builtInMatches.length > 1) {
95
- className = builtInMatches[1];
96
- } else {
97
- // Failed to match the standard '[object ClassName]'
98
- return toString.call(val);
99
- }
100
- if (className == 'Object') {
101
- // we're a user defined class or Object
102
- // JSON.stringify avoids problems with cycles, and is generally much
103
- // easier than looping through ownProperties of `val`.
104
- try {
105
- return 'Object(' + JSON.stringify(val) + ')';
106
- } catch (_) {
107
- return 'Object';
108
- }
109
- }
110
- // errors
111
- if (val instanceof Error) {
112
- return `${val.name}: ${val.message}\n${val.stack}`;
113
- }
114
- // TODO we could test for more things here, like `Set`s and `Map`s.
115
- return className;
116
- }
117
-
118
- let WASM_VECTOR_LEN = 0;
119
-
120
- let cachedTextEncoder = new TextEncoder('utf-8');
121
-
122
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
123
- ? function (arg, view) {
124
- return cachedTextEncoder.encodeInto(arg, view);
125
- }
126
- : function (arg, view) {
127
- const buf = cachedTextEncoder.encode(arg);
128
- view.set(buf);
129
- return {
130
- read: arg.length,
131
- written: buf.length
132
- };
133
- });
134
-
135
- function passStringToWasm0(arg, malloc, realloc) {
136
-
137
- if (realloc === undefined) {
138
- const buf = cachedTextEncoder.encode(arg);
139
- const ptr = malloc(buf.length, 1) >>> 0;
140
- getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
141
- WASM_VECTOR_LEN = buf.length;
142
- return ptr;
143
- }
144
-
145
- let len = arg.length;
146
- let ptr = malloc(len, 1) >>> 0;
147
-
148
- const mem = getUint8Memory0();
149
-
150
- let offset = 0;
151
-
152
- for (; offset < len; offset++) {
153
- const code = arg.charCodeAt(offset);
154
- if (code > 0x7F) break;
155
- mem[ptr + offset] = code;
156
- }
157
-
158
- if (offset !== len) {
159
- if (offset !== 0) {
160
- arg = arg.slice(offset);
161
- }
162
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
163
- const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
164
- const ret = encodeString(arg, view);
165
-
166
- offset += ret.written;
167
- ptr = realloc(ptr, len, offset, 1) >>> 0;
168
- }
169
-
170
- WASM_VECTOR_LEN = offset;
171
- return ptr;
172
- }
173
-
174
- let cachedInt32Memory0 = null;
175
-
176
- function getInt32Memory0() {
177
- if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
178
- cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
179
- }
180
- return cachedInt32Memory0;
181
- }
182
-
183
- let cachedUint32Memory0 = null;
184
-
185
- function getUint32Memory0() {
186
- if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
187
- cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
188
- }
189
- return cachedUint32Memory0;
190
- }
191
-
192
- function getArrayJsValueFromWasm0(ptr, len) {
193
- ptr = ptr >>> 0;
194
- const mem = getUint32Memory0();
195
- const slice = mem.subarray(ptr / 4, ptr / 4 + len);
196
- const result = [];
197
- for (let i = 0; i < slice.length; i++) {
198
- result.push(takeObject(slice[i]));
199
- }
200
- return result;
201
- }
202
- /**
203
- * @param {string} schema
204
- * @returns {any[]}
205
- */
206
- module.exports.validate_connect_directives = function(schema) {
207
- try {
208
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
209
- const ptr0 = passStringToWasm0(schema, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
210
- const len0 = WASM_VECTOR_LEN;
211
- wasm.validate_connect_directives(retptr, ptr0, len0);
212
- var r0 = getInt32Memory0()[retptr / 4 + 0];
213
- var r1 = getInt32Memory0()[retptr / 4 + 1];
214
- var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
215
- wasm.__wbindgen_free(r0, r1 * 4, 4);
216
- return v2;
217
- } finally {
218
- wasm.__wbindgen_add_to_stack_pointer(16);
219
- }
220
- };
221
-
222
- function handleError(f, args) {
223
- try {
224
- return f.apply(this, args);
225
- } catch (e) {
226
- wasm.__wbindgen_exn_store(addHeapObject(e));
227
- }
228
- }
229
-
230
- module.exports.__wbindgen_object_drop_ref = function(arg0) {
231
- takeObject(arg0);
232
- };
233
-
234
- module.exports.__wbindgen_string_new = function(arg0, arg1) {
235
- const ret = getStringFromWasm0(arg0, arg1);
236
- return addHeapObject(ret);
237
- };
238
-
239
- module.exports.__wbindgen_number_new = function(arg0) {
240
- const ret = arg0;
241
- return addHeapObject(ret);
242
- };
243
-
244
- module.exports.__wbindgen_object_clone_ref = function(arg0) {
245
- const ret = getObject(arg0);
246
- return addHeapObject(ret);
247
- };
248
-
249
- module.exports.__wbg_new_72fb9a18b5ae2624 = function() {
250
- const ret = new Object();
251
- return addHeapObject(ret);
252
- };
253
-
254
- module.exports.__wbg_set_1f9b04f170055d33 = function() { return handleError(function (arg0, arg1, arg2) {
255
- const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
256
- return ret;
257
- }, arguments) };
258
-
259
- module.exports.__wbindgen_debug_string = function(arg0, arg1) {
260
- const ret = debugString(getObject(arg1));
261
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
262
- const len1 = WASM_VECTOR_LEN;
263
- getInt32Memory0()[arg0 / 4 + 1] = len1;
264
- getInt32Memory0()[arg0 / 4 + 0] = ptr1;
265
- };
266
-
267
- module.exports.__wbindgen_throw = function(arg0, arg1) {
268
- throw new Error(getStringFromWasm0(arg0, arg1));
269
- };
270
-
271
- const path = require('path').join(__dirname, 'federation_internals_wasm_bg.wasm');
272
- const bytes = require('fs').readFileSync(path);
273
-
274
- const wasmModule = new WebAssembly.Module(bytes);
275
- const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
276
- wasm = wasmInstance.exports;
277
- module.exports.__wasm = wasm;
278
-