@asod/field 0.1.0-canary.1 → 0.1.0-canary.2

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/dist/core.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import ASOD from '@asod/core';
2
+
3
+ declare module '@asod/core' {
4
+ namespace Operation {
5
+ interface IComparable {
6
+ comparator?: ASOD.Comparator;
7
+ }
8
+
9
+ interface IOperationObjectValue extends IComparable {}
10
+
11
+ type OperationValue = Primitive | IOperationObjectValue;
12
+
13
+ interface IOperation<TValue extends OperationValue> {
14
+ (...values: [TValue, ...TValue[]]): TValue;
15
+ }
16
+
17
+ interface IBinaryOperation<TValue extends OperationValue>
18
+ extends IOperation<TValue> {
19
+ (a: TValue, b: TValue): TValue;
20
+ }
21
+ }
22
+
23
+ namespace Ring {
24
+ interface IRing<TValue extends OperationValue> {
25
+ add: IOperation<TValue>;
26
+ mul: IOperation<TValue>;
27
+ }
28
+ }
29
+
30
+ namespace Field {
31
+ interface IField<TValue extends OperationValue> extends IRing<TValue> {
32
+ sub: IOperation<TValue>;
33
+ div: IOperation<TValue>;
34
+ }
35
+ }
36
+ }
37
+
38
+ export = ASOD;
39
+ export as namespace ASOD;
package/dist/field.d.ts CHANGED
@@ -1,25 +1,23 @@
1
- import { type Field } from './declarations/index';
2
- type FieldOperationConfig<TValue extends Field.OperationValue> = {
3
- func: Field.IOperation<TValue>;
1
+ import type ASOD from './core';
2
+ import { Ring } from './ring';
3
+ type FieldOperationConfig<TValue extends ASOD.Operation.OperationValue> = {
4
+ func: ASOD.Operation.IBinaryOperation<TValue>;
4
5
  neutralValue: TValue;
5
6
  };
6
- type FieldOperationsConfig<TValue extends Field.OperationValue> = {
7
+ type FieldOperationsConfig<TValue extends ASOD.Operation.OperationValue> = {
7
8
  add: FieldOperationConfig<TValue>;
8
9
  sub: FieldOperationConfig<TValue>;
9
10
  mul: FieldOperationConfig<TValue>;
10
11
  div: FieldOperationConfig<TValue>;
11
12
  };
12
- type FieldConfig<TValue extends Field.OperationValue> = {
13
+ type FieldConfig<TValue extends ASOD.Operation.OperationValue> = {
13
14
  operations: FieldOperationsConfig<TValue>;
14
15
  };
15
- declare class Field<TValue extends Field.OperationValue> implements Field.IField<TValue> {
16
- private readonly _operations;
16
+ declare class Field<TValue extends ASOD.Operation.OperationValue> extends Ring<TValue> implements ASOD.Field.IField<TValue> {
17
+ protected readonly _operations: Readonly<FieldOperationsConfig<TValue>>;
17
18
  constructor(config: FieldConfig<TValue>);
18
- add(a: TValue, b: TValue): TValue;
19
19
  sub(a: TValue, b: TValue): TValue;
20
- mul(a: TValue, b: TValue): TValue;
21
20
  div(a: TValue, b: TValue): TValue;
22
- private _compare;
23
21
  }
24
22
  export { Field };
25
23
  export default Field;
package/dist/field.js CHANGED
@@ -16,8 +16,7 @@ _export(exports, {
16
16
  return _default;
17
17
  }
18
18
  });
19
- const _compare = require("@asod/compare");
20
- const _guards = require("./utils/guards");
19
+ const _ring = require("./ring");
21
20
  function _define_property(obj, key, value) {
22
21
  if (key in obj) {
23
22
  Object.defineProperty(obj, key, {
@@ -31,36 +30,19 @@ function _define_property(obj, key, value) {
31
30
  }
32
31
  return obj;
33
32
  }
34
- class Field {
35
- add(a, b) {
36
- const { func, neutralValue } = this._operations.add;
37
- if (!this._compare(a, neutralValue)) return b;
38
- if (!this._compare(b, neutralValue)) return a;
39
- return func(a, b);
40
- }
33
+ class Field extends _ring.Ring {
41
34
  sub(a, b) {
42
35
  const { func, neutralValue } = this._operations.sub;
43
36
  if (!this._compare(b, neutralValue)) return a;
44
37
  return func(a, b);
45
38
  }
46
- mul(a, b) {
47
- const { func, neutralValue } = this._operations.mul;
48
- if (!this._compare(a, neutralValue)) return b;
49
- if (!this._compare(b, neutralValue)) return a;
50
- return func(a, b);
51
- }
52
39
  div(a, b) {
53
40
  const { func, neutralValue } = this._operations.div;
54
41
  if (!this._compare(b, neutralValue)) return a;
55
42
  return func(a, b);
56
43
  }
57
- _compare(a, b) {
58
- if ((0, _guards.isComparable)(a)) return (0, _compare.compare)(a, b, a.comparator);
59
- if ((0, _guards.isComparable)(b)) return (0, _compare.compare)(a, b, b.comparator);
60
- return (0, _compare.compare)(a, b);
61
- }
62
44
  constructor(config){
63
- _define_property(this, "_operations", void 0);
45
+ super(config), _define_property(this, "_operations", void 0);
64
46
  this._operations = config.operations;
65
47
  }
66
48
  }
package/dist/index.d.ts CHANGED
@@ -1,53 +1,2 @@
1
- /// <reference path="global.d.ts" />
2
-
3
- import ASOD from '@asod/core';
4
- import { type Comparator } from '@asod/compare';
5
-
6
- declare const ABSTRACT_OPERATION_ID: unique symbol;
7
-
8
- type AbstractOperationId = typeof ABSTRACT_OPERATION_ID;
9
-
10
- declare module '@asod/core' {
11
- namespace Field {
12
- /* Common */
13
-
14
- interface IComparable {
15
- comparator?: Comparator;
16
- }
17
-
18
- /* Operation */
19
-
20
- interface IOperationValue extends IComparable {}
21
-
22
- type OperationValue = Primitive | IOperationValue;
23
-
24
- interface IOperation<TValue extends OperationValue> {
25
- (a: TValue, b: TValue): TValue;
26
- }
27
-
28
- /* Group */
29
-
30
- interface IGroup<TValue extends OperationValue> {
31
- [ABSTRACT_OPERATION_ID]: IOperation<TValue>;
32
- }
33
-
34
- /* Ring */
35
-
36
- // prettier-ignore
37
- interface IRing<TValue extends OperationValue> extends Omit<IGroup<TValue>, AbstractOperationId> {
38
- add: IOperation<TValue>;
39
- mul: IOperation<TValue>;
40
- }
41
-
42
- /* Field */
43
-
44
- // prettier-ignore
45
- interface IField<TValue extends OperationValue> extends Omit<IRing<TValue>, AbstractOperationId> {
46
- sub: IOperation<TValue>;
47
- div: IOperation<TValue>;
48
- }
49
- }
50
- }
51
-
52
- export = ASOD;
53
- export as namespace ASOD;
1
+ export * from './ring';
2
+ export * from './field';
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./ring"), exports);
6
+ _export_star(require("./field"), exports);
7
+ function _export_star(from, to) {
8
+ Object.keys(from).forEach(function(k) {
9
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
10
+ Object.defineProperty(to, k, {
11
+ enumerable: true,
12
+ get: function() {
13
+ return from[k];
14
+ }
15
+ });
16
+ }
17
+ });
18
+ return from;
19
+ }
package/dist/ring.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import type ASOD from './core';
2
+ type RingOperationConfig<TValue extends ASOD.Operation.OperationValue> = {
3
+ func: ASOD.Operation.IBinaryOperation<TValue>;
4
+ neutralValue: TValue;
5
+ };
6
+ type RingOperationsConfig<TValue extends ASOD.Operation.OperationValue> = {
7
+ add: RingOperationConfig<TValue>;
8
+ mul: RingOperationConfig<TValue>;
9
+ };
10
+ type RingConfig<TValue extends ASOD.Operation.OperationValue> = {
11
+ operations: RingOperationsConfig<TValue>;
12
+ };
13
+ declare class Ring<TValue extends ASOD.Operation.OperationValue> implements ASOD.Ring.IRing<TValue> {
14
+ protected readonly _operations: Readonly<RingOperationsConfig<TValue>>;
15
+ constructor(config: RingConfig<TValue>);
16
+ add(a: TValue, b: TValue): TValue;
17
+ mul(a: TValue, b: TValue): TValue;
18
+ protected _compare(a: TValue, b: TValue): number;
19
+ }
20
+ export { Ring };
21
+ export default Ring;
package/dist/ring.js ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get Ring () {
13
+ return Ring;
14
+ },
15
+ get default () {
16
+ return _default;
17
+ }
18
+ });
19
+ const _compare = require("@asod/compare");
20
+ const _guards = require("./utils/guards");
21
+ function _define_property(obj, key, value) {
22
+ if (key in obj) {
23
+ Object.defineProperty(obj, key, {
24
+ value: value,
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true
28
+ });
29
+ } else {
30
+ obj[key] = value;
31
+ }
32
+ return obj;
33
+ }
34
+ class Ring {
35
+ add(a, b) {
36
+ const { func, neutralValue } = this._operations.add;
37
+ if (!this._compare(a, neutralValue)) return b;
38
+ if (!this._compare(b, neutralValue)) return a;
39
+ return func(a, b);
40
+ }
41
+ mul(a, b) {
42
+ const { func, neutralValue } = this._operations.mul;
43
+ if (!this._compare(a, neutralValue)) return b;
44
+ if (!this._compare(b, neutralValue)) return a;
45
+ return func(a, b);
46
+ }
47
+ _compare(a, b) {
48
+ if ((0, _guards.isComparable)(a)) return (0, _compare.compare)(a, b, a.comparator);
49
+ if ((0, _guards.isComparable)(b)) return (0, _compare.compare)(a, b, b.comparator);
50
+ return (0, _compare.compare)(a, b);
51
+ }
52
+ constructor(config){
53
+ _define_property(this, "_operations", void 0);
54
+ this._operations = config.operations;
55
+ }
56
+ }
57
+ const _default = Ring;
@@ -1,2 +1,2 @@
1
- import { type Field } from '../declarations/index';
2
- export declare const isComparable: (value: Field.OperationValue) => value is Field.IComparable;
1
+ import type ASOD from '../core';
2
+ export declare const isComparable: (value: ASOD.Operation.OperationValue) => value is ASOD.Operation.IComparable;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@asod/field",
3
3
  "description": "",
4
- "version": "0.1.0-canary.1",
4
+ "version": "0.1.0-canary.2",
5
5
  "license": "MIT",
6
6
  "author": "Oleg Putseiko <oleg.putseiko@gmail.com> (https://github.com/oleg-putseiko)",
7
7
  "keywords": [],
@@ -21,7 +21,7 @@
21
21
  "scripts": {
22
22
  "build": "yarn build:js && yarn build:ts",
23
23
  "build:js": "swc src -d dist --strip-leading-paths --ignore \"node_modules,**/*.test.ts,**/*.d.ts\"",
24
- "build:ts": "tsc && find src -name \"*.d.ts\" -exec cp {} dist/ \\;",
24
+ "build:ts": "tsc && mkdir -p dist && find src -name \"*.d.ts\" -exec cp {} dist/ \\;",
25
25
  "lint": "eslint ./src/**/*.ts -c ./eslint.config.mjs",
26
26
  "lint:fix": "yarn lint --fix && yarn format:fix",
27
27
  "lint:strict": "yarn lint --max-warnings=0 && yarn format",
@@ -32,6 +32,10 @@
32
32
  "prepare": "husky install | chmod +x ./.husky/*",
33
33
  "version:bump": "npm version -m \"build(package): bump the package version to %s\""
34
34
  },
35
+ "dependencies": {
36
+ "@asod/compare": "^0.1.1-canary.5",
37
+ "@asod/core": "^0.1.0-canary.1"
38
+ },
35
39
  "devDependencies": {
36
40
  "@commitlint/cli": "^18.2.0",
37
41
  "@commitlint/config-conventional": "^18.1.0",
@@ -54,9 +58,5 @@
54
58
  "volta": {
55
59
  "node": "20.19.5",
56
60
  "yarn": "4.10.3"
57
- },
58
- "dependencies": {
59
- "@asod/compare": "^0.1.1-canary.1",
60
- "@asod/core": "^0.1.0-canary.0"
61
61
  }
62
62
  }