mle-js-plsql-ffi 23.7.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.
package/LICENSE.txt ADDED
@@ -0,0 +1,35 @@
1
+ Copyright (c) 2024, 2025, Oracle and/or its affiliates.
2
+
3
+ The Universal Permissive License (UPL), Version 1.0
4
+
5
+ Subject to the condition set forth below, permission is hereby granted to any
6
+ person obtaining a copy of this software, associated documentation and/or data
7
+ (collectively the "Software"), free of charge and under any and all copyright
8
+ rights in the Software, and any and all patent rights owned or freely
9
+ licensable by each licensor hereunder covering either (i) the unmodified
10
+ Software as contributed to or provided by such licensor, or (ii) the Larger
11
+ Works (as defined below), to deal in both
12
+
13
+ (a) the Software, and
14
+ (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15
+ one is included with the Software (each a "Larger Work" to which the Software
16
+ is contributed by such licensors),
17
+
18
+ without restriction, including without limitation the rights to copy, create
19
+ derivative works of, display, perform, and distribute the Software and make,
20
+ use, sell, offer for sale, import, export, have made, and have sold the
21
+ Software and the Larger Work(s), and to sublicense the foregoing rights on
22
+ either these or other terms.
23
+
24
+ This license is subject to the following condition:
25
+ The above copyright notice and either this complete permission notice or at
26
+ a minimum a reference to the UPL must be included in all copies or
27
+ substantial portions of the Software.
28
+
29
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ Please consult the installation instructions and documentation on https://oracle-samples.github.io/mle-modules.
package/args.d.ts ADDED
@@ -0,0 +1,107 @@
1
+ /**
2
+ Copyright (c) 2024, 2025, Oracle and/or its affiliates.
3
+
4
+ The Universal Permissive License (UPL), Version 1.0
5
+
6
+ Subject to the condition set forth below, permission is hereby granted to any
7
+ person obtaining a copy of this software, associated documentation and/or data
8
+ (collectively the "Software"), free of charge and under any and all copyright
9
+ rights in the Software, and any and all patent rights owned or freely
10
+ licensable by each licensor hereunder covering either (i) the unmodified
11
+ Software as contributed to or provided by such licensor, or (ii) the Larger
12
+ Works (as defined below), to deal in both
13
+
14
+ (a) the Software, and
15
+ (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16
+ one is included with the Software (each a "Larger Work" to which the Software
17
+ is contributed by such licensors),
18
+
19
+ without restriction, including without limitation the rights to copy, create
20
+ derivative works of, display, perform, and distribute the Software and make,
21
+ use, sell, offer for sale, import, export, have made, and have sold the
22
+ Software and the Larger Work(s), and to sublicense the foregoing rights on
23
+ either these or other terms.
24
+
25
+ This license is subject to the following condition:
26
+ The above copyright notice and either this complete permission notice or at
27
+ a minimum a reference to the UPL must be included in all copies or
28
+ substantial portions of the Software.
29
+
30
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
+ SOFTWARE.
37
+ */
38
+ /**
39
+ * Argument description.
40
+ */
41
+ export type ArgInfo = {
42
+ /**
43
+ * The value of the argument.
44
+ */
45
+ val?: any;
46
+ /**
47
+ * The maximum number of bytes an argument with OUT values can take up.
48
+ * Default: 200.
49
+ */
50
+ maxSize?: number;
51
+ /**
52
+ * The argument direction. In almost all cases this is not necessary and the
53
+ * direction chosen by the FFI should be used.
54
+ * Accepted values:
55
+ * - oracledb.BIND_IN
56
+ * - oracledb.BIND_OUT
57
+ * - oracledb.BIND_INOUT.
58
+ */
59
+ dir?: number;
60
+ /**
61
+ * If the type chosen by FFI needs to be changed this property can be used.
62
+ * This property needs to be set to either an oracledb type constant or to
63
+ * the name of the database type in case of a user defined named type (e.g.
64
+ * record or object).
65
+ * This can be useful to ensure no precision loss when e.g. retrieving
66
+ * a number (by specifying the oracledb.ORACLE_NUMBER override).
67
+ * It can also be useful to specify the correct overload if the FFI cannot
68
+ * determine the correct subprogram to use in a package.
69
+ * @remarks
70
+ * Named types are case sensitive.
71
+ */
72
+ type?: number | string;
73
+ /**
74
+ * The number of array elements to be allocated for a PL/SQL INDEX BY associative array.
75
+ * @remarks
76
+ * Needed for all OUT associative array arguments.
77
+ * INDEX BY VARCHAR2 associative arrays are **not** supported.
78
+ */
79
+ maxArraySize?: number;
80
+ };
81
+ /**
82
+ * This interface represents an argument for a PL/SQL call.
83
+ * It can act as a value holder for arguments that have an OUT value.
84
+ * It can also act as an extra information store about the given values.
85
+ * This could be the type, maxSize, direction or maxArraySize.
86
+ */
87
+ export interface DBArgument {
88
+ /**
89
+ * The JavaScript value of the PL/SQL argument.
90
+ */
91
+ val: any;
92
+ }
93
+ /**
94
+ * Create a new argument, to be used in a subsequent PL/SQL call.
95
+ * @param info optional argument description.
96
+ * @returns the JavaScript representation of a PL/SQL argument.
97
+ */
98
+ export declare function arg(info?: ArgInfo): DBArgument;
99
+ /**
100
+ * Create a new argument with the given value.
101
+ * @param value the value of the argument.
102
+ * @param info optional argument description.
103
+ * @returns the JavaScript representation of a PL/SQL argument.
104
+ * @remarks
105
+ * If info contains a val property it will be ignored.
106
+ */
107
+ export declare function argOf(value: any, info?: ArgInfo): DBArgument;
@@ -0,0 +1,58 @@
1
+ /**
2
+ Copyright (c) 2024, Oracle and/or its affiliates.
3
+
4
+ The Universal Permissive License (UPL), Version 1.0
5
+
6
+ Subject to the condition set forth below, permission is hereby granted to any
7
+ person obtaining a copy of this software, associated documentation and/or data
8
+ (collectively the "Software"), free of charge and under any and all copyright
9
+ rights in the Software, and any and all patent rights owned or freely
10
+ licensable by each licensor hereunder covering either (i) the unmodified
11
+ Software as contributed to or provided by such licensor, or (ii) the Larger
12
+ Works (as defined below), to deal in both
13
+
14
+ (a) the Software, and
15
+ (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16
+ one is included with the Software (each a "Larger Work" to which the Software
17
+ is contributed by such licensors),
18
+
19
+ without restriction, including without limitation the rights to copy, create
20
+ derivative works of, display, perform, and distribute the Software and make,
21
+ use, sell, offer for sale, import, export, have made, and have sold the
22
+ Software and the Larger Work(s), and to sublicense the foregoing rights on
23
+ either these or other terms.
24
+
25
+ This license is subject to the following condition:
26
+ The above copyright notice and either this complete permission notice or at
27
+ a minimum a reference to the UPL must be included in all copies or
28
+ substantial portions of the Software.
29
+
30
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
+ SOFTWARE.
37
+ */
38
+ /**
39
+ * This class represents a PL/SQL exception that occurred during the execution
40
+ * of a PL/SQL subprogram.
41
+ * @extends Error
42
+ */
43
+ export declare class CallError extends Error {
44
+ #private;
45
+ /**
46
+ * The Error type returned by the FFI if an issue occurs.
47
+ * @param code the Oracle error code
48
+ * @param msg the error message
49
+ * @private
50
+ */
51
+ constructor(code: number, msg: string);
52
+ /**
53
+ * Returns true if this CallError is the given PL/SQL exception.
54
+ * @param errorCode the Oracle error code of the exception.
55
+ * @returns whether this instance represents the given PL/SQL exception.
56
+ */
57
+ is(errorCode: number): boolean;
58
+ }
package/index.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ Copyright (c) 2024, Oracle and/or its affiliates.
3
+
4
+ The Universal Permissive License (UPL), Version 1.0
5
+
6
+ Subject to the condition set forth below, permission is hereby granted to any
7
+ person obtaining a copy of this software, associated documentation and/or data
8
+ (collectively the "Software"), free of charge and under any and all copyright
9
+ rights in the Software, and any and all patent rights owned or freely
10
+ licensable by each licensor hereunder covering either (i) the unmodified
11
+ Software as contributed to or provided by such licensor, or (ii) the Larger
12
+ Works (as defined below), to deal in both
13
+
14
+ (a) the Software, and
15
+ (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16
+ one is included with the Software (each a "Larger Work" to which the Software
17
+ is contributed by such licensors),
18
+
19
+ without restriction, including without limitation the rights to copy, create
20
+ derivative works of, display, perform, and distribute the Software and make,
21
+ use, sell, offer for sale, import, export, have made, and have sold the
22
+ Software and the Larger Work(s), and to sublicense the foregoing rights on
23
+ either these or other terms.
24
+
25
+ This license is subject to the following condition:
26
+ The above copyright notice and either this complete permission notice or at
27
+ a minimum a reference to the UPL must be included in all copies or
28
+ substantial portions of the Software.
29
+
30
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
+ SOFTWARE.
37
+ */
38
+ import { DBArgument, arg, argOf } from './args';
39
+ import { CallError } from './call-error';
40
+ import { resolvePackage, resolveFunction, resolveProcedure } from './resolvers';
41
+ export type { DBArgument };
42
+ export { arg, argOf, CallError, resolvePackage, resolveFunction, resolveProcedure, };
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "mle-js-plsql-ffi",
3
+ "description": "MLE Foreign Function Interface (FFI): API for calling PL/SQL functionality directly",
4
+ "types": "index.d.ts",
5
+ "author": "Oracle",
6
+ "version": "23.7.0",
7
+ "license": "UPL-1.0",
8
+ "homepage": "https://oracle-samples.github.io/mle-modules",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git://github.com/oracle-samples/mle-modules"
12
+ },
13
+ "bugs": "https://github.com/oracle-samples/mle-modules/issues"
14
+ }
package/resolvers.d.ts ADDED
@@ -0,0 +1,104 @@
1
+ /**
2
+ Copyright (c) 2024, Oracle and/or its affiliates.
3
+
4
+ The Universal Permissive License (UPL), Version 1.0
5
+
6
+ Subject to the condition set forth below, permission is hereby granted to any
7
+ person obtaining a copy of this software, associated documentation and/or data
8
+ (collectively the "Software"), free of charge and under any and all copyright
9
+ rights in the Software, and any and all patent rights owned or freely
10
+ licensable by each licensor hereunder covering either (i) the unmodified
11
+ Software as contributed to or provided by such licensor, or (ii) the Larger
12
+ Works (as defined below), to deal in both
13
+
14
+ (a) the Software, and
15
+ (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16
+ one is included with the Software (each a "Larger Work" to which the Software
17
+ is contributed by such licensors),
18
+
19
+ without restriction, including without limitation the rights to copy, create
20
+ derivative works of, display, perform, and distribute the Software and make,
21
+ use, sell, offer for sale, import, export, have made, and have sold the
22
+ Software and the Larger Work(s), and to sublicense the foregoing rights on
23
+ either these or other terms.
24
+
25
+ This license is subject to the following condition:
26
+ The above copyright notice and either this complete permission notice or at
27
+ a minimum a reference to the UPL must be included in all copies or
28
+ substantial portions of the Software.
29
+
30
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
+ SOFTWARE.
37
+ */
38
+ import { DBSubprogram } from './subprogram-api';
39
+ /**
40
+ * @categoryDescription Resolve Functions
41
+ * These functions resolve PL/SQL objects by name.
42
+ * The name can optionally contain the schema divided by a dot e.g. SCOTT.THING.
43
+ * If the schema is not given the usual PL/SQL name resolution rules apply.
44
+ * @module
45
+ */
46
+ /**
47
+ * Resolve a PL/SQL package by name.
48
+ *
49
+ * @returns a representation of the given package that can be used to interact
50
+ * with the PL/SQL package.
51
+ *
52
+ * @category Resolve Functions
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * // Get the JS represenation.
57
+ * const dbmsRandom = resolvePackage('DBMS_RANDOM');
58
+ *
59
+ * // Use the representation.
60
+ * dbmsRandom.seed(42);
61
+ * console.log(dbmsRandom.normal());
62
+ * ```
63
+ */
64
+ export declare function resolvePackage(name: string): any;
65
+ /**
66
+ * Resolve a PL/SQL top-level function by name.
67
+ *
68
+ * @returns a JavaScript function that will execute the PL/SQL function when
69
+ * called and returns the PL/SQL return value.
70
+ *
71
+ * @category Resolve Functions
72
+ *
73
+ * @remarks
74
+ * Similarly to the SQL driver this package has to deal with translating types
75
+ * between PL/SQL and JavaScript. Some PL/SQL types can be translated into
76
+ * multiple JavaScript types, so the return type can be overridden.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * // Resolve top-level function.
81
+ * const exampleFunc = resolveFunction('my_func');
82
+ * // Execute the PL/SQL function simply by calling the JS function.
83
+ * const numberResult = exampleFunc(42);
84
+ * // Override the return type of the function.
85
+ * const oracleNumberResult = exampleFunc.returns(oracledb.ORACLE_NUMBER)(42);
86
+ * ```
87
+ */
88
+ export declare function resolveFunction(name: string): DBSubprogram;
89
+ /**
90
+ * Resolve a PL/SQL top-level procedure.
91
+ *
92
+ * @returns a JavaScript function that will execute the given PL/SQL procedure
93
+ * when called.
94
+ *
95
+ * @category Resolve Functions
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * // Resolve the procedure
100
+ * const exampleProcedure = resolveProcedure('my_procedure');
101
+ * exampleProcedure(42, 23);
102
+ * ```
103
+ */
104
+ export declare function resolveProcedure(name: string): DBSubprogram;
@@ -0,0 +1,71 @@
1
+ /**
2
+ Copyright (c) 2024, Oracle and/or its affiliates.
3
+
4
+ The Universal Permissive License (UPL), Version 1.0
5
+
6
+ Subject to the condition set forth below, permission is hereby granted to any
7
+ person obtaining a copy of this software, associated documentation and/or data
8
+ (collectively the "Software"), free of charge and under any and all copyright
9
+ rights in the Software, and any and all patent rights owned or freely
10
+ licensable by each licensor hereunder covering either (i) the unmodified
11
+ Software as contributed to or provided by such licensor, or (ii) the Larger
12
+ Works (as defined below), to deal in both
13
+
14
+ (a) the Software, and
15
+ (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16
+ one is included with the Software (each a "Larger Work" to which the Software
17
+ is contributed by such licensors),
18
+
19
+ without restriction, including without limitation the rights to copy, create
20
+ derivative works of, display, perform, and distribute the Software and make,
21
+ use, sell, offer for sale, import, export, have made, and have sold the
22
+ Software and the Larger Work(s), and to sublicense the foregoing rights on
23
+ either these or other terms.
24
+
25
+ This license is subject to the following condition:
26
+ The above copyright notice and either this complete permission notice or at
27
+ a minimum a reference to the UPL must be included in all copies or
28
+ substantial portions of the Software.
29
+
30
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
+ SOFTWARE.
37
+ */
38
+ /**
39
+ * Return type override options.
40
+ */
41
+ export type ReturnInfo = {
42
+ /**
43
+ * The same as {@link ArgInfo.maxSize}.
44
+ */
45
+ maxSize?: number;
46
+ /**
47
+ * The same as {@link ArgInfo.type}.
48
+ */
49
+ type?: number | string;
50
+ /**
51
+ * The same as {@link ArgInfo.maxArraySize}.
52
+ */
53
+ maxArraySize?: number;
54
+ };
55
+ /**
56
+ * JavaScript representation of a PL/SQL subprogram.
57
+ */
58
+ export interface DBSubprogram {
59
+ (...arg: any[]): any;
60
+ /**
61
+ * Override the return type of the subprogram.
62
+ * If the subprogram being represented is a procedure this has no effect.
63
+ * @param dbType the database type. This needs to be either an oracledb
64
+ * type constant or a string containing the name of a user defined database
65
+ * type (only for named types like records and objects).
66
+ * If more info needs to be specified {@link ReturnInfo} can be used.
67
+ * @remarks
68
+ * Type names are case-sensitive.
69
+ */
70
+ overrideReturnType(dbType: number | string | ReturnInfo): DBSubprogram;
71
+ }