graphile-build-pg 4.12.2 → 4.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -3
- package/node8plus/omit.js +1 -1
- package/node8plus/omit.js.flow +1 -1
- package/node8plus/omit.js.map +1 -1
- package/node8plus/plugins/PgComputedColumnsPlugin.js +1 -1
- package/node8plus/plugins/PgComputedColumnsPlugin.js.flow +1 -1
- package/node8plus/plugins/PgComputedColumnsPlugin.js.map +1 -1
- package/node8plus/plugins/PgIntrospectionPlugin.js +2 -2
- package/node8plus/plugins/PgIntrospectionPlugin.js.flow +2 -2
- package/node8plus/plugins/PgIntrospectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgRecordReturnTypesPlugin.js +1 -1
- package/node8plus/plugins/PgRecordReturnTypesPlugin.js.flow +1 -1
- package/node8plus/plugins/PgRecordReturnTypesPlugin.js.map +1 -1
- package/node8plus/plugins/PgTypesPlugin.js +7 -7
- package/node8plus/plugins/PgTypesPlugin.js.flow +7 -7
- package/node8plus/plugins/PgTypesPlugin.js.map +1 -1
- package/node8plus/utils.js +1 -1
- package/node8plus/utils.js.flow +1 -1
- package/node8plus/utils.js.map +1 -1
- package/package.json +4 -4
|
@@ -65,7 +65,7 @@ var PgRecordReturnTypesPlugin = function PgRecordReturnTypesPlugin(builder) {
|
|
|
65
65
|
const isMutation = !proc.isStable;
|
|
66
66
|
const firstArgType = argTypes[0];
|
|
67
67
|
const computed = firstArgType && firstArgType.type === "c" && firstArgType.class && firstArgType.namespaceId === proc.namespaceId && proc.name.startsWith(`${firstArgType.name}_`);
|
|
68
|
-
const procFieldName = isMutation ? inflection.functionMutationName(proc) : computed ? inflection.computedColumn(proc.name.
|
|
68
|
+
const procFieldName = isMutation ? inflection.functionMutationName(proc) : computed ? inflection.computedColumn(proc.name.slice(firstArgType.name.length + 1), proc) : inflection.functionQueryName(proc);
|
|
69
69
|
newWithHooks(GraphQLObjectType, {
|
|
70
70
|
name: inflection.recordFunctionReturnType(proc),
|
|
71
71
|
description: build.wrapDescription(`The return type of our \`${procFieldName}\` ${isMutation ? "mutation" : "query"}.`, "type"),
|
|
@@ -71,7 +71,7 @@ export default (function PgRecordReturnTypesPlugin(builder) {
|
|
|
71
71
|
? inflection.functionMutationName(proc)
|
|
72
72
|
: computed
|
|
73
73
|
? inflection.computedColumn(
|
|
74
|
-
proc.name.
|
|
74
|
+
proc.name.slice(firstArgType.name.length + 1),
|
|
75
75
|
proc
|
|
76
76
|
)
|
|
77
77
|
: inflection.functionQueryName(proc);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/PgRecordReturnTypesPlugin.js"],"names":["PgRecordReturnTypesPlugin","builder","hook","_","build","newWithHooks","pgIntrospectionResultsByKind","introspectionResultsByKind","pgGetGqlTypeByTypeIdAndModifier","graphql","GraphQLObjectType","inflection","pgOmit","omit","describePgEntity","sqlCommentByAddingTags","pgSql","sql","pgGetSelectValueForFieldAndTypeAndModifier","getSelectValueForFieldAndTypeAndModifier","getSafeAliasFromResolveInfo","getSafeAliasFromAlias","pg2gqlForType","procedure","forEach","proc","namespace","returnType","typeById","returnTypeId","id","argTypes","argTypeIds","reduce","prev","typeId","idx","argModes","length","push","argModesWithOutput","outputArgNames","includes","argNames","outputArgTypes","isMutation","isStable","firstArgType","computed","type","class","namespaceId","name","startsWith","procFieldName","functionMutationName","computedColumn","substr","functionQueryName","recordFunctionReturnType","description","wrapDescription","fields","fieldWithHooks","memo","outputArgName","fieldName","functionOutputFieldName","fieldType","Error","fieldContext","addDataGenerator","parsedResolveInfoFragment","safeAlias","alias","pgQuery","queryBuilder","select","fragment","getTableAlias","identifier","convertFromPg","resolve","data","_args","_context","resolveInfo","__origin","resultTypeName","isRecordReturnType","pgIntrospection"],"mappings":";;;;;;;IAGyBA,yB,GAAT,SAASA,yBAAT,CAAmCC,OAAnC,EAA4C;AAC1DA,EAAAA,OAAO,CAACC,IAAR,CACE,MADF,EAE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AAAA,eAAe,EAAEjE;AAfnB,OA3EU,CAAZ;AA6FD,KAlJD;AAmJA,WAAOtB,CAAP;AACD,GAxKH,EAyKE,CAAC,qBAAD,CAzKF;AA2KD,C","sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\n\nexport default (function PgRecordReturnTypesPlugin(builder) {\n builder.hook(\n \"init\",\n (_, build) => {\n const {\n newWithHooks,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n pgGetGqlTypeByTypeIdAndModifier,\n graphql: { GraphQLObjectType },\n inflection,\n pgOmit: omit,\n describePgEntity,\n sqlCommentByAddingTags,\n pgSql: sql,\n pgGetSelectValueForFieldAndTypeAndModifier:\n getSelectValueForFieldAndTypeAndModifier,\n getSafeAliasFromResolveInfo,\n getSafeAliasFromAlias,\n pg2gqlForType,\n } = build;\n\n introspectionResultsByKind.procedure.forEach(proc => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!proc.namespace) return;\n if (omit(proc, \"execute\")) return;\n\n const returnType =\n introspectionResultsByKind.typeById[proc.returnTypeId];\n if (returnType.id !== \"2249\") {\n return;\n }\n const argTypes = proc.argTypeIds.reduce((prev, typeId, idx) => {\n if (\n proc.argModes.length === 0 || // all args are `in`\n proc.argModes[idx] === \"i\" || // this arg is `in`\n proc.argModes[idx] === \"b\" // this arg is `inout`\n ) {\n prev.push(introspectionResultsByKind.typeById[typeId]);\n }\n return prev;\n }, []);\n const argModesWithOutput = [\n \"o\", // OUT,\n \"b\", // INOUT\n \"t\", // TABLE\n ];\n const outputArgNames = proc.argTypeIds.reduce((prev, _, idx) => {\n if (argModesWithOutput.includes(proc.argModes[idx])) {\n prev.push(proc.argNames[idx] || \"\");\n }\n return prev;\n }, []);\n const outputArgTypes = proc.argTypeIds.reduce((prev, typeId, idx) => {\n if (argModesWithOutput.includes(proc.argModes[idx])) {\n prev.push(introspectionResultsByKind.typeById[typeId]);\n }\n return prev;\n }, []);\n const isMutation = !proc.isStable;\n const firstArgType = argTypes[0];\n const computed =\n firstArgType &&\n firstArgType.type === \"c\" &&\n firstArgType.class &&\n firstArgType.namespaceId === proc.namespaceId &&\n proc.name.startsWith(`${firstArgType.name}_`);\n const procFieldName = isMutation\n ? inflection.functionMutationName(proc)\n : computed\n ? inflection.computedColumn(\n proc.name.substr(firstArgType.name.length + 1),\n proc\n )\n : inflection.functionQueryName(proc);\n newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.recordFunctionReturnType(proc),\n description: build.wrapDescription(\n `The return type of our \\`${procFieldName}\\` ${\n isMutation ? \"mutation\" : \"query\"\n }.`,\n \"type\"\n ),\n fields: ({ fieldWithHooks }) => {\n return outputArgNames.reduce((memo, outputArgName, idx) => {\n const fieldName = inflection.functionOutputFieldName(\n proc,\n outputArgName,\n idx + 1\n );\n const fieldType = pgGetGqlTypeByTypeIdAndModifier(\n outputArgTypes[idx].id,\n null\n );\n if (memo[fieldName]) {\n throw new Error(\n `Tried to register field name '${fieldName}' twice in '${describePgEntity(\n proc\n )}'; the argument names are too similar.`\n );\n }\n memo[fieldName] = fieldWithHooks(\n fieldName,\n fieldContext => {\n const { addDataGenerator } = fieldContext;\n addDataGenerator(parsedResolveInfoFragment => {\n const safeAlias = getSafeAliasFromAlias(\n parsedResolveInfoFragment.alias\n );\n return {\n pgQuery: queryBuilder => {\n queryBuilder.select(\n getSelectValueForFieldAndTypeAndModifier(\n fieldType,\n fieldContext,\n parsedResolveInfoFragment,\n sql.fragment`(${queryBuilder.getTableAlias()}.${sql.identifier(\n // According to https://www.postgresql.org/docs/10/static/sql-createfunction.html,\n // \"If you omit the name for an output argument, the system will choose a default column name.\"\n // In PG 9.x and 10, the column names appear to be assigned with a `column` prefix.\n outputArgName !== \"\"\n ? outputArgName\n : `column${idx + 1}`\n )})`,\n outputArgTypes[idx],\n null\n ),\n safeAlias\n );\n },\n };\n });\n const convertFromPg = pg2gqlForType(outputArgTypes[idx]);\n return {\n type: fieldType,\n resolve(data, _args, _context, resolveInfo) {\n const safeAlias =\n getSafeAliasFromResolveInfo(resolveInfo);\n return convertFromPg(data[safeAlias]);\n },\n };\n },\n {}\n );\n return memo;\n }, {});\n },\n },\n {\n __origin: `Adding record return type for ${describePgEntity(\n proc\n )}. You can rename the function's GraphQL field (and its dependent types) via a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n proc,\n {\n name: \"newNameHere\",\n }\n )}\\n\\nYou can rename just the function's GraphQL result type via a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n proc,\n {\n resultTypeName: \"newNameHere\",\n }\n )}`,\n isRecordReturnType: true,\n pgIntrospection: proc,\n }\n );\n });\n return _;\n },\n [\"PgRecordReturnTypes\"]\n );\n}: Plugin);\n"],"file":"PgRecordReturnTypesPlugin.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/PgRecordReturnTypesPlugin.js"],"names":["PgRecordReturnTypesPlugin","builder","hook","_","build","newWithHooks","pgIntrospectionResultsByKind","introspectionResultsByKind","pgGetGqlTypeByTypeIdAndModifier","graphql","GraphQLObjectType","inflection","pgOmit","omit","describePgEntity","sqlCommentByAddingTags","pgSql","sql","pgGetSelectValueForFieldAndTypeAndModifier","getSelectValueForFieldAndTypeAndModifier","getSafeAliasFromResolveInfo","getSafeAliasFromAlias","pg2gqlForType","procedure","forEach","proc","namespace","returnType","typeById","returnTypeId","id","argTypes","argTypeIds","reduce","prev","typeId","idx","argModes","length","push","argModesWithOutput","outputArgNames","includes","argNames","outputArgTypes","isMutation","isStable","firstArgType","computed","type","class","namespaceId","name","startsWith","procFieldName","functionMutationName","computedColumn","slice","functionQueryName","recordFunctionReturnType","description","wrapDescription","fields","fieldWithHooks","memo","outputArgName","fieldName","functionOutputFieldName","fieldType","Error","fieldContext","addDataGenerator","parsedResolveInfoFragment","safeAlias","alias","pgQuery","queryBuilder","select","fragment","getTableAlias","identifier","convertFromPg","resolve","data","_args","_context","resolveInfo","__origin","resultTypeName","isRecordReturnType","pgIntrospection"],"mappings":";;;;;;;IAGyBA,yB,GAAT,S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Ac,EAAE;AADlB,SAF+G,CAK/G,EAbJ;AAcEC,QAAAA,kBAAkB,EAAE,IAdtB;AAeEC,QAAAA,eAAe,EAAEjE;AAfnB,OA3EU,CAAZ;AA6FD,KAlJD;AAmJA,WAAOtB,CAAP;AACD,GAxKH,EAyKE,CAAC,qBAAD,CAzKF;AA2KD,C","sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\n\nexport default (function PgRecordReturnTypesPlugin(builder) {\n builder.hook(\n \"init\",\n (_, build) => {\n const {\n newWithHooks,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n pgGetGqlTypeByTypeIdAndModifier,\n graphql: { GraphQLObjectType },\n inflection,\n pgOmit: omit,\n describePgEntity,\n sqlCommentByAddingTags,\n pgSql: sql,\n pgGetSelectValueForFieldAndTypeAndModifier:\n getSelectValueForFieldAndTypeAndModifier,\n getSafeAliasFromResolveInfo,\n getSafeAliasFromAlias,\n pg2gqlForType,\n } = build;\n\n introspectionResultsByKind.procedure.forEach(proc => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!proc.namespace) return;\n if (omit(proc, \"execute\")) return;\n\n const returnType =\n introspectionResultsByKind.typeById[proc.returnTypeId];\n if (returnType.id !== \"2249\") {\n return;\n }\n const argTypes = proc.argTypeIds.reduce((prev, typeId, idx) => {\n if (\n proc.argModes.length === 0 || // all args are `in`\n proc.argModes[idx] === \"i\" || // this arg is `in`\n proc.argModes[idx] === \"b\" // this arg is `inout`\n ) {\n prev.push(introspectionResultsByKind.typeById[typeId]);\n }\n return prev;\n }, []);\n const argModesWithOutput = [\n \"o\", // OUT,\n \"b\", // INOUT\n \"t\", // TABLE\n ];\n const outputArgNames = proc.argTypeIds.reduce((prev, _, idx) => {\n if (argModesWithOutput.includes(proc.argModes[idx])) {\n prev.push(proc.argNames[idx] || \"\");\n }\n return prev;\n }, []);\n const outputArgTypes = proc.argTypeIds.reduce((prev, typeId, idx) => {\n if (argModesWithOutput.includes(proc.argModes[idx])) {\n prev.push(introspectionResultsByKind.typeById[typeId]);\n }\n return prev;\n }, []);\n const isMutation = !proc.isStable;\n const firstArgType = argTypes[0];\n const computed =\n firstArgType &&\n firstArgType.type === \"c\" &&\n firstArgType.class &&\n firstArgType.namespaceId === proc.namespaceId &&\n proc.name.startsWith(`${firstArgType.name}_`);\n const procFieldName = isMutation\n ? inflection.functionMutationName(proc)\n : computed\n ? inflection.computedColumn(\n proc.name.slice(firstArgType.name.length + 1),\n proc\n )\n : inflection.functionQueryName(proc);\n newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.recordFunctionReturnType(proc),\n description: build.wrapDescription(\n `The return type of our \\`${procFieldName}\\` ${\n isMutation ? \"mutation\" : \"query\"\n }.`,\n \"type\"\n ),\n fields: ({ fieldWithHooks }) => {\n return outputArgNames.reduce((memo, outputArgName, idx) => {\n const fieldName = inflection.functionOutputFieldName(\n proc,\n outputArgName,\n idx + 1\n );\n const fieldType = pgGetGqlTypeByTypeIdAndModifier(\n outputArgTypes[idx].id,\n null\n );\n if (memo[fieldName]) {\n throw new Error(\n `Tried to register field name '${fieldName}' twice in '${describePgEntity(\n proc\n )}'; the argument names are too similar.`\n );\n }\n memo[fieldName] = fieldWithHooks(\n fieldName,\n fieldContext => {\n const { addDataGenerator } = fieldContext;\n addDataGenerator(parsedResolveInfoFragment => {\n const safeAlias = getSafeAliasFromAlias(\n parsedResolveInfoFragment.alias\n );\n return {\n pgQuery: queryBuilder => {\n queryBuilder.select(\n getSelectValueForFieldAndTypeAndModifier(\n fieldType,\n fieldContext,\n parsedResolveInfoFragment,\n sql.fragment`(${queryBuilder.getTableAlias()}.${sql.identifier(\n // According to https://www.postgresql.org/docs/10/static/sql-createfunction.html,\n // \"If you omit the name for an output argument, the system will choose a default column name.\"\n // In PG 9.x and 10, the column names appear to be assigned with a `column` prefix.\n outputArgName !== \"\"\n ? outputArgName\n : `column${idx + 1}`\n )})`,\n outputArgTypes[idx],\n null\n ),\n safeAlias\n );\n },\n };\n });\n const convertFromPg = pg2gqlForType(outputArgTypes[idx]);\n return {\n type: fieldType,\n resolve(data, _args, _context, resolveInfo) {\n const safeAlias =\n getSafeAliasFromResolveInfo(resolveInfo);\n return convertFromPg(data[safeAlias]);\n },\n };\n },\n {}\n );\n return memo;\n }, {});\n },\n },\n {\n __origin: `Adding record return type for ${describePgEntity(\n proc\n )}. You can rename the function's GraphQL field (and its dependent types) via a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n proc,\n {\n name: \"newNameHere\",\n }\n )}\\n\\nYou can rename just the function's GraphQL result type via a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n proc,\n {\n resultTypeName: \"newNameHere\",\n }\n )}`,\n isRecordReturnType: true,\n pgIntrospection: proc,\n }\n );\n });\n return _;\n },\n [\"PgRecordReturnTypes\"]\n );\n}: Plugin);\n"],"file":"PgRecordReturnTypesPlugin.js"}
|
|
@@ -503,7 +503,7 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
|
|
|
503
503
|
pg2GqlMapper[600] = {
|
|
504
504
|
map: f => {
|
|
505
505
|
if (f[0] === "(" && f[f.length - 1] === ")") {
|
|
506
|
-
const [x, y] = f.
|
|
506
|
+
const [x, y] = f.slice(1, -1).split(",").map(f => parseFloat(f));
|
|
507
507
|
return {
|
|
508
508
|
x,
|
|
509
509
|
y
|
|
@@ -1088,7 +1088,7 @@ end`;
|
|
|
1088
1088
|
pg2GqlMapper[LINE] = {
|
|
1089
1089
|
map: f => {
|
|
1090
1090
|
if (f[0] === "{" && f[f.length - 1] === "}") {
|
|
1091
|
-
const [A, B, C] = f.
|
|
1091
|
+
const [A, B, C] = f.slice(1, -1).split(",").map(f => parseFloat(f)); // Lines have the form Ax + By + C = 0.
|
|
1092
1092
|
// So if y = 0, Ax + C = 0; x = -C/A.
|
|
1093
1093
|
// If x = 0, By + C = 0; y = -C/B.
|
|
1094
1094
|
|
|
@@ -1139,7 +1139,7 @@ end`;
|
|
|
1139
1139
|
pg2GqlMapper[LSEG] = {
|
|
1140
1140
|
map: f => {
|
|
1141
1141
|
if (f[0] === "[" && f[f.length - 1] === "]") {
|
|
1142
|
-
const [x1, y1, x2, y2] = f.
|
|
1142
|
+
const [x1, y1, x2, y2] = f.slice(1, -1).replace(/[()]/g, "").split(",").map(f => parseFloat(f));
|
|
1143
1143
|
return {
|
|
1144
1144
|
a: {
|
|
1145
1145
|
x: x1,
|
|
@@ -1187,7 +1187,7 @@ end`;
|
|
|
1187
1187
|
pg2GqlMapper[BOX] = {
|
|
1188
1188
|
map: f => {
|
|
1189
1189
|
if (f[0] === "(" && f[f.length - 1] === ")") {
|
|
1190
|
-
const [x1, y1, x2, y2] = f.
|
|
1190
|
+
const [x1, y1, x2, y2] = f.slice(1, -1).replace(/[()]/g, "").split(",").map(f => parseFloat(f));
|
|
1191
1191
|
return {
|
|
1192
1192
|
a: {
|
|
1193
1193
|
x: x1,
|
|
@@ -1245,7 +1245,7 @@ end`;
|
|
|
1245
1245
|
}
|
|
1246
1246
|
|
|
1247
1247
|
if (isOpen !== null) {
|
|
1248
|
-
const xsAndYs = f.
|
|
1248
|
+
const xsAndYs = f.slice(1, -1).replace(/[()]/g, "").split(",").map(f => parseFloat(f));
|
|
1249
1249
|
|
|
1250
1250
|
if (xsAndYs.length % 2 !== 0) {
|
|
1251
1251
|
throw new Error("Invalid path representation");
|
|
@@ -1298,7 +1298,7 @@ end`;
|
|
|
1298
1298
|
pg2GqlMapper[POLYGON] = {
|
|
1299
1299
|
map: f => {
|
|
1300
1300
|
if (f[0] === "(" && f[f.length - 1] === ")") {
|
|
1301
|
-
const xsAndYs = f.
|
|
1301
|
+
const xsAndYs = f.slice(1, -1).replace(/[()]/g, "").split(",").map(f => parseFloat(f));
|
|
1302
1302
|
|
|
1303
1303
|
if (xsAndYs.length % 2 !== 0) {
|
|
1304
1304
|
throw new Error("Invalid polygon representation");
|
|
@@ -1354,7 +1354,7 @@ end`;
|
|
|
1354
1354
|
pg2GqlMapper[CIRCLE] = {
|
|
1355
1355
|
map: f => {
|
|
1356
1356
|
if (f[0] === "<" && f[f.length - 1] === ">") {
|
|
1357
|
-
const [x, y, r] = f.
|
|
1357
|
+
const [x, y, r] = f.slice(1, -1).replace(/[()]/g, "").split(",").map(f => parseFloat(f));
|
|
1358
1358
|
return {
|
|
1359
1359
|
center: {
|
|
1360
1360
|
x,
|
|
@@ -687,7 +687,7 @@ export default (function PgTypesPlugin(
|
|
|
687
687
|
map: f => {
|
|
688
688
|
if (f[0] === "(" && f[f.length - 1] === ")") {
|
|
689
689
|
const [x, y] = f
|
|
690
|
-
.
|
|
690
|
+
.slice(1, -1)
|
|
691
691
|
.split(",")
|
|
692
692
|
.map(f => parseFloat(f));
|
|
693
693
|
return { x, y };
|
|
@@ -1434,7 +1434,7 @@ end`;
|
|
|
1434
1434
|
map: f => {
|
|
1435
1435
|
if (f[0] === "{" && f[f.length - 1] === "}") {
|
|
1436
1436
|
const [A, B, C] = f
|
|
1437
|
-
.
|
|
1437
|
+
.slice(1, -1)
|
|
1438
1438
|
.split(",")
|
|
1439
1439
|
.map(f => parseFloat(f));
|
|
1440
1440
|
// Lines have the form Ax + By + C = 0.
|
|
@@ -1484,7 +1484,7 @@ end`;
|
|
|
1484
1484
|
map: f => {
|
|
1485
1485
|
if (f[0] === "[" && f[f.length - 1] === "]") {
|
|
1486
1486
|
const [x1, y1, x2, y2] = f
|
|
1487
|
-
.
|
|
1487
|
+
.slice(1, -1)
|
|
1488
1488
|
.replace(/[()]/g, "")
|
|
1489
1489
|
.split(",")
|
|
1490
1490
|
.map(f => parseFloat(f));
|
|
@@ -1532,7 +1532,7 @@ end`;
|
|
|
1532
1532
|
map: f => {
|
|
1533
1533
|
if (f[0] === "(" && f[f.length - 1] === ")") {
|
|
1534
1534
|
const [x1, y1, x2, y2] = f
|
|
1535
|
-
.
|
|
1535
|
+
.slice(1, -1)
|
|
1536
1536
|
.replace(/[()]/g, "")
|
|
1537
1537
|
.split(",")
|
|
1538
1538
|
.map(f => parseFloat(f));
|
|
@@ -1602,7 +1602,7 @@ end`;
|
|
|
1602
1602
|
}
|
|
1603
1603
|
if (isOpen !== null) {
|
|
1604
1604
|
const xsAndYs = f
|
|
1605
|
-
.
|
|
1605
|
+
.slice(1, -1)
|
|
1606
1606
|
.replace(/[()]/g, "")
|
|
1607
1607
|
.split(",")
|
|
1608
1608
|
.map(f => parseFloat(f));
|
|
@@ -1655,7 +1655,7 @@ end`;
|
|
|
1655
1655
|
map: f => {
|
|
1656
1656
|
if (f[0] === "(" && f[f.length - 1] === ")") {
|
|
1657
1657
|
const xsAndYs = f
|
|
1658
|
-
.
|
|
1658
|
+
.slice(1, -1)
|
|
1659
1659
|
.replace(/[()]/g, "")
|
|
1660
1660
|
.split(",")
|
|
1661
1661
|
.map(f => parseFloat(f));
|
|
@@ -1701,7 +1701,7 @@ end`;
|
|
|
1701
1701
|
map: f => {
|
|
1702
1702
|
if (f[0] === "<" && f[f.length - 1] === ">") {
|
|
1703
1703
|
const [x, y, r] = f
|
|
1704
|
-
.
|
|
1704
|
+
.slice(1, -1)
|
|
1705
1705
|
.replace(/[()]/g, "")
|
|
1706
1706
|
.split(",")
|
|
1707
1707
|
.map(f => parseFloat(f));
|