@cpzxrobot/sdk 1.3.68 → 1.3.70

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.
@@ -9,7 +9,7 @@ export class MobilePlatform implements PlatformInterface {
9
9
  token: string = "";
10
10
  appCode: string = "";
11
11
  baseURL: string = "";
12
- private port: MessagePort | null = null;
12
+ // private port: MessagePort | null = null;
13
13
 
14
14
  constructor() {
15
15
  // @ts-ignore
@@ -25,10 +25,10 @@ export class MobilePlatform implements PlatformInterface {
25
25
  getToken(): string {
26
26
  return "";
27
27
  }
28
- setToken(token: string): void {
28
+ setToken(_token: string): void {
29
29
  }
30
30
 
31
- setSelectedFarm(farm: Factory): void {
31
+ setSelectedFarm(_farm: Factory): void {
32
32
  throw new Error("Method not implemented.");
33
33
  }
34
34
  setSelectedUnit(unit: Unit): void {
package/news_gateway.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Cpzxrobot, Factory, Unit } from "./types";
1
+ import { Cpzxrobot } from "./types";
2
2
 
3
3
  export class NewsGateway extends Object {
4
4
  context: Cpzxrobot;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.68",
3
+ "version": "1.3.70",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/sensor_datas.ts CHANGED
@@ -13,11 +13,19 @@ export class FieldDatas {
13
13
  valuesAt(at: string) {
14
14
  var values: Map<string, any> = new Map();
15
15
  for (var i = 0; i < this.values.length; i++) {
16
- if (this.values[i][this.columns.get("_time")!] == at) {
17
- var field = this.values[i][this.columns.get("_field")!];
18
- var value = this.values[i][this.columns.get("_value")!];
19
- values.set(field, value);
20
- break;
16
+ var timeIndex = this.columns.get("_time");
17
+ var fieldIndex = this.columns.get("_field");
18
+ var valueIndex = this.columns.get("_value");
19
+
20
+ if (timeIndex !== undefined && fieldIndex !== undefined && valueIndex !== undefined) {
21
+ if (this.values[i] && this.values[i]![timeIndex] == at) {
22
+ var field = this.values[i]![fieldIndex];
23
+ var value = this.values[i]![valueIndex];
24
+ if (field !== undefined) {
25
+ values.set(field, value);
26
+ }
27
+ break;
28
+ }
21
29
  }
22
30
  }
23
31
  return values;
@@ -26,9 +34,12 @@ export class FieldDatas {
26
34
  get fields() {
27
35
  var fields: string[] = ["time"];
28
36
  for (var i = 0; i < this.values.length; i++) {
29
- var field = this.values[i][this.columns.get("_field")!];
30
- if (fields.indexOf(field) == -1) {
31
- fields.push(field);
37
+ var fieldIndex = this.columns.get("_field");
38
+ if (fieldIndex !== undefined) {
39
+ var field = this.values[i]![fieldIndex];
40
+ if (field !== undefined && fields.indexOf(field) == -1) {
41
+ fields.push(field);
42
+ }
32
43
  }
33
44
  }
34
45
  return fields;
@@ -48,17 +59,16 @@ export class SensorDatas {
48
59
  }[] = [];
49
60
  if (!this.data_fields) return datas;
50
61
  if (this.data_fields.length == 0) return datas;
51
- for (var i = 0; i < this.data_fields[0].values.length; i++) {
62
+ for (var i = 0; i < this.data_fields[0]!.values.length; i++) {
63
+ var timeIndex = this.data_fields[0]!.columns.get("_time");
52
64
  var data: {
53
65
  time: string;
54
66
  [key: string]: any;
55
67
  } = {
56
- time: this.data_fields[0].values[i][
57
- this.data_fields[0].columns.get("_time")!
58
- ],
68
+ time: timeIndex !== undefined ? this.data_fields[0]!.values[i]![timeIndex]! : "",
59
69
  };
60
70
  for (var j = 0; j < this.data_fields.length; j++) {
61
- var field = this.data_fields[j];
71
+ var field = this.data_fields[j]!;
62
72
  var values = field.valuesAt(data.time);
63
73
  for (let [key, value] of values.entries()) {
64
74
  data[key] = value;
@@ -72,10 +82,11 @@ export class SensorDatas {
72
82
  get fields() {
73
83
  var fields: string[] = [];
74
84
  for (var i = 0; i < this.data_fields.length; i++) {
75
- var subfields = this.data_fields[i].fields;
85
+ var subfields = this.data_fields[i]!.fields;
76
86
  for (var j = 0; j < subfields.length; j++) {
77
- if (fields.indexOf(subfields[j]) == -1) {
78
- fields.push(subfields[j]);
87
+ var field = subfields[j];
88
+ if (field !== undefined && fields.indexOf(field) == -1) {
89
+ fields.push(field);
79
90
  }
80
91
  }
81
92
  }
package/test_strict.ts ADDED
@@ -0,0 +1,22 @@
1
+ // 测试严格类型检查的文件
2
+ // import { FieldDatas } from './sensor_datas';
3
+
4
+ // 测试未修复前的代码模式
5
+ function testUnsafeCode() {
6
+ // const fieldData = new FieldDatas();
7
+
8
+ // 模拟未修复前的代码模式
9
+ const map = new Map<string, number>();
10
+
11
+ // 这会触发类型错误(如果strictNullChecks启用)
12
+ // const unsafeValue = map.get("nonexistent")!; // 使用!操作符
13
+ // console.log(unsafeValue);
14
+
15
+ // 安全的代码模式
16
+ const safeValue = map.get("nonexistent");
17
+ if (safeValue !== undefined) {
18
+ console.log(safeValue);
19
+ }
20
+ }
21
+
22
+ testUnsafeCode();
package/tsconfig.json CHANGED
@@ -11,8 +11,8 @@
11
11
  // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
12
 
13
13
  /* Language and Environment */
14
- "target": "es2017", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
- "lib": ["es2017","dom"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
14
+ "target": "es2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
+ "lib": ["es2017","dom","es2015.collection"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
16
  // "jsx": "preserve", /* Specify what JSX code is generated. */
17
17
  // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18
18
  // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
@@ -59,7 +59,7 @@
59
59
  // "removeComments": true, /* Disable emitting comments. */
60
60
  // "noEmit": true, /* Disable emitting files from a compilation. */
61
61
  // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
62
- // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
62
+ "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
63
63
  // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
64
64
  // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
65
65
  // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
@@ -82,22 +82,22 @@
82
82
 
83
83
  /* Type Checking */
84
84
  "strict": true, /* Enable all strict type-checking options. */
85
- // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
86
- // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
87
- // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
88
- // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
89
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
90
- // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
91
- // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
92
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
93
- // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
94
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
95
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
96
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
97
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
98
- // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
99
- // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
100
- // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
85
+ "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
86
+ "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
87
+ "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
88
+ "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
89
+ "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
90
+ "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
91
+ "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
92
+ "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
93
+ "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
94
+ "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
95
+ "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
96
+ "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
97
+ "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
98
+ "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
99
+ "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
100
+ "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
101
101
  // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
102
102
  // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
103
103
 
package/types.d.ts CHANGED
@@ -34,7 +34,6 @@ type Device = {
34
34
  location: string;
35
35
  supplier?: string;
36
36
  data?: any;
37
- typeCode: string;
38
37
  unitId: number;
39
38
  };
40
39
 
@@ -82,7 +81,7 @@ type FodderOrderInTower = {
82
81
 
83
82
  type Assistant = {
84
83
  info: String;
85
- status: String;
84
+ status: Number;
86
85
  name: String;
87
86
  id: Number;
88
87
  };
@@ -95,10 +94,11 @@ type Factory = {
95
94
  kind?: string;
96
95
  pid?: number;
97
96
  business_kind?: string;
97
+ path?: string;
98
98
  };
99
99
  type Unit = {
100
100
  name?: string;
101
- id?: number;
101
+ id: number;
102
102
  type?: string;
103
103
  workshopName?: string;
104
104
  workshopId?: number;
@@ -145,20 +145,9 @@ type DeviceConfig = {
145
145
  type?: string;
146
146
  };
147
147
 
148
- type FieldDatas = {
149
- length: number;
150
- valuesAt(at: string): Map<string, any>;
151
- fields: string[];
152
- };
153
148
 
154
- type SensorDatas = {
155
- push: (data: FieldDatas) => void;
156
- datas: {
157
- time: string;
158
- [key: string]: any;
159
- }[];
160
- fields: string[];
161
- };
149
+
150
+
162
151
 
163
152
  type Electricity = {
164
153
  deviceId: string;
@@ -220,11 +209,7 @@ type weightMeterSensorsConfig = {
220
209
  sensors: WeightMeterSensor[];
221
210
  };
222
211
 
223
- type WeightMeterSensor = {
224
- address: number;
225
- adzero: number;
226
- hornScale: number;
227
- };
212
+
228
213
 
229
214
  // {
230
215
  //     "id":1,
@@ -326,12 +311,7 @@ interface Supplier {
326
311
  updatedAt?: Date;
327
312
  }
328
313
 
329
- interface Assistant {
330
- info: String;
331
- status: Number;
332
- name: String;
333
- id: Number;
334
- }
314
+
335
315
  interface ElectricMeter extends Device {
336
316
  coefficient: number;
337
317
  status: string;
@@ -390,7 +370,7 @@ interface DataQueryArgs {
390
370
  aggerate?: string;
391
371
  }
392
372
 
393
- class Cpzxrobot {
373
+ declare class Cpzxrobot {
394
374
  transport: TransportGateway;
395
375
  ready: Promise<MyAxiosInstance>;
396
376
  factory: FactoryGateway;
@@ -442,31 +422,15 @@ declare global {
442
422
 
443
423
  declare module "@cpzxrobot/sdk" {
444
424
  export default function (
445
- args: {
425
+ args?: {
446
426
  devAuth: string;
447
427
  baseURL?: string;
448
428
  appCode: string;
449
- selectedFarm: Factory | null | undefined;
450
- selectedUnit: Unit | null | undefined;
429
+ selectedFarm?: Factory | null | undefined;
430
+ selectedUnit?: Unit | null | undefined;
451
431
  verbose?: boolean;
452
432
  disableFactorySelector?: boolean;
453
- } = {
454
- devAuth: "",
455
- appCode: "",
456
- baseURL: "https://www.cpzxrobot.com/",
457
- selectedFarm: {
458
- id: 0,
459
- code: "",
460
- name: "",
461
- company_code: "",
462
- },
463
- selectedUnit: {
464
- id: 0,
465
- name: "",
466
- },
467
- verbose: false,
468
- disableFactorySelector: false,
469
- }
433
+ }
470
434
  ): Cpzxrobot;
471
435
  export {
472
436
  Cpzxrobot,
@@ -489,7 +453,7 @@ declare module "@cpzxrobot/sdk" {
489
453
  HeatLamp,
490
454
  DeviceV2,
491
455
  FieldDatas,
492
- SensorDatas,
456
+
493
457
  ElectricMeterRate,
494
458
  DevicePurpose,
495
459
  };
package/web_platform.ts CHANGED
@@ -14,7 +14,7 @@ export class WebPlatform implements PlatformInterface {
14
14
  this._selectedFarm = selectedFarm;
15
15
  this._selectedUnit = selectedUnit;
16
16
  }
17
- addMessage(message: any): void {
17
+ addMessage(_message: any): void {
18
18
  throw new Error("Method not implemented.");
19
19
  }
20
20
  getToken(): string {
@@ -80,7 +80,7 @@ export class WebPlatform implements PlatformInterface {
80
80
  } else if (line.startsWith("data: ")) {
81
81
  // remove prefix 'data: '
82
82
  // 移除前缀 'data: '
83
- var data = JSON.parse(line.split(": ")[1]);
83
+ var data = JSON.parse(line.split(": ")[1]!);
84
84
  //{"choices":[{"delta":{"content":" </"},"index":0}],"created":1741749068,"id":"chatcmpl-67ccb889154043f5874cbf3a64ec163e","model":"DeepSeek-R1","object":"chat.completion.chunk"}
85
85
  fn?.(data);
86
86
  }
@@ -189,10 +189,10 @@ export class WebPlatform implements PlatformInterface {
189
189
  if (contentDisposition) {
190
190
  const utf8FilenameMatch = contentDisposition.match(/filename\*=UTF-8''(.+)/i);
191
191
  if (utf8FilenameMatch) {
192
- filename = decodeURIComponent(utf8FilenameMatch[1]);
192
+ filename = decodeURIComponent(utf8FilenameMatch[1]!);
193
193
  } else {
194
194
  const filenameMatch = contentDisposition.match(/filename="?(.+?)"?(;|$)/i);
195
- if (filenameMatch) filename = filenameMatch[1];
195
+ if (filenameMatch) filename = filenameMatch[1]!;
196
196
  }
197
197
  } else {
198
198
  filename = "file"
@@ -220,10 +220,10 @@ export class WebPlatform implements PlatformInterface {
220
220
  if (contentDisposition) {
221
221
  const utf8FilenameMatch = contentDisposition.match(/filename\*=UTF-8''(.+)/i);
222
222
  if (utf8FilenameMatch) {
223
- filename = decodeURIComponent(utf8FilenameMatch[1]);
223
+ filename = decodeURIComponent(utf8FilenameMatch[1]!);
224
224
  } else {
225
225
  const filenameMatch = contentDisposition.match(/filename="?(.+?)"?(;|$)/i);
226
- if (filenameMatch) filename = filenameMatch[1];
226
+ if (filenameMatch) filename = filenameMatch[1]!;
227
227
  }
228
228
  } else {
229
229
  filename = "file";
@@ -289,7 +289,7 @@ export class WebPlatform implements PlatformInterface {
289
289
  return { data: blob };
290
290
  },
291
291
  upload: async (url: string, option?: any) => {
292
- return new Promise<any>((resolve, reject) => {
292
+ return new Promise<any>((resolve, _reject) => {
293
293
  const button = document.createElement("input");
294
294
  button.type = "file";
295
295
  button.style.display = "none";
@@ -302,10 +302,10 @@ export class WebPlatform implements PlatformInterface {
302
302
  const formData = new FormData();
303
303
  if (option?.multiple) {
304
304
  for (let i = 0; i < files.length; i++) {
305
- formData.append("files[]", files[i]);
305
+ formData.append("files[]", files[i]!);
306
306
  }
307
307
  } else {
308
- formData.append(option?.["fileField"] || "file", files[0]);
308
+ formData.append(option?.["fileField"] || "file", files[0]!);
309
309
  }
310
310
  for (let key in option?.["data"]) {
311
311
  formData.append(key, option!["data"][key]);
@@ -323,7 +323,7 @@ export class WebPlatform implements PlatformInterface {
323
323
  };
324
324
  });
325
325
  },
326
- getAsSse: (url: string, fn: any, config?: {
326
+ getAsSse: (url: string, fn: any, _config?: {
327
327
  fileName?: string;
328
328
  params?: any;
329
329
  preview?: boolean;
@@ -399,11 +399,11 @@ export class WebPlatform implements PlatformInterface {
399
399
  }
400
400
  }
401
401
 
402
- showInDeviceManager(deviceId: any, type: string): Promise<void> {
402
+ showInDeviceManager(_deviceId: any, _type: string): Promise<void> {
403
403
  return Promise.resolve();
404
404
  }
405
405
 
406
- reloadGroup(key: string): void {
406
+ reloadGroup(_key: string): void {
407
407
  // No implementation in web platform
408
408
  }
409
409
 
@@ -427,11 +427,11 @@ export class WebPlatform implements PlatformInterface {
427
427
  });
428
428
  }
429
429
 
430
- setResult(name: string, value: any): void {
430
+ setResult(_name: string, _value: any): void {
431
431
  // No implementation in web platform
432
432
  }
433
433
 
434
- setResultAs(name: string, value: any, type: string): void {
434
+ setResultAs(_name: string, _value: any, _type: string): void {
435
435
  // No implementation in web platform
436
436
  }
437
437
 
@@ -439,7 +439,7 @@ export class WebPlatform implements PlatformInterface {
439
439
  console.error(message);
440
440
  }
441
441
 
442
- setProgress(precentage: number): void {
442
+ setProgress(_precentage: number): void {
443
443
  // No implementation in web platform
444
444
  }
445
445
  }
@@ -2,7 +2,7 @@ import { PlatformInterface } from "./platform_interface";
2
2
  import { Factory, MyAxiosInstance, Unit } from "./types";
3
3
 
4
4
  export class WindwosMiniAppPlatform implements PlatformInterface {
5
- private messagePort?: MessagePort;
5
+ // private messagePort?: MessagePort;
6
6
  private sseCallbacks: { [key: string]: (data: any) => void } = {};
7
7
  token: string = "";
8
8
  appCode: string = "";
@@ -20,9 +20,9 @@ export class WindwosMiniAppPlatform implements PlatformInterface {
20
20
  getToken(): string {
21
21
  return "";
22
22
  }
23
- setToken(token: string): void {
23
+ setToken(_token: string): void {
24
24
  }
25
- setSelectedFarm(farm: Factory): void {
25
+ setSelectedFarm(_farm: Factory): void {
26
26
  throw new Error("Method not implemented.");
27
27
  }
28
28
  setSelectedUnit(unit: Unit): void {